Also emit TokenKind in debug

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-08 20:05:54 +01:00
parent 13eb4ca1d0
commit 08b480705b
14 changed files with 205 additions and 205 deletions

View file

@ -456,7 +456,7 @@ mod tests {
TemplateAst {
root: [
StaticContent(
"Hello World" (0..11),
[Content]"Hello World" (0..11),
),
],
}
@ -475,14 +475,14 @@ mod tests {
TemplateAst {
root: [
StaticContent(
"Hello" (0..5),
[Content]"Hello" (0..5),
),
Interpolation {
prev_whitespace_content: Some(
" " (5..6),
[Whitespace]" " (5..6),
),
expression: VariableAccess(
"world" (10..15),
[Ident]"world" (10..15),
),
post_whitespace_content: None,
},
@ -508,20 +508,20 @@ mod tests {
if_block: Block {
prev_whitespace_content: None,
expression: VariableAccess(
"foo" (6..9),
[Ident]"foo" (6..9),
),
post_whitespace_content: Some(
" " (12..13),
[Whitespace]" " (12..13),
),
},
content: [
StaticContent(
"Hiii" (13..17),
[Content]"Hiii" (13..17),
),
],
end_block: Block {
prev_whitespace_content: Some(
" " (17..18),
[Whitespace]" " (17..18),
),
expression: EndBlock,
post_whitespace_content: None,
@ -604,11 +604,11 @@ mod tests {
insta::assert_debug_snapshot!(result, @r#"
(
[
"{{" (0..2),
" " (2..3),
"foo" (3..6),
" " (6..7),
"}}" (7..9),
[LeftDelim]"{{" (0..2),
[Whitespace]" " (2..3),
[Ident]"foo" (3..6),
[Whitespace]" " (6..7),
[RightDelim]"}}" (7..9),
],
None,
[

View file

@ -10,10 +10,10 @@ TemplateAst {
if_block: Block {
prev_whitespace_content: None,
expression: VariableAccess(
"foo" (6..9),
[Ident]"foo" (6..9),
),
post_whitespace_content: Some(
"\n " (12..25),
[Whitespace]"\n " (12..25),
),
},
content: [
@ -23,24 +23,24 @@ TemplateAst {
if_block: Block {
prev_whitespace_content: None,
expression: VariableAccess(
"bar" (31..34),
[Ident]"bar" (31..34),
),
post_whitespace_content: Some(
"\n " (37..54),
[Whitespace]"\n " (37..54),
),
},
content: [
StaticContent(
"Hiii" (54..58),
[Content]"Hiii" (54..58),
),
],
end_block: Block {
prev_whitespace_content: Some(
"\n " (58..71),
[Whitespace]"\n " (58..71),
),
expression: EndBlock,
post_whitespace_content: Some(
"\n " (80..89),
[Whitespace]"\n " (80..89),
),
},
},
@ -51,7 +51,7 @@ TemplateAst {
prev_whitespace_content: None,
expression: EndBlock,
post_whitespace_content: Some(
"\n\n " (98..108),
[Whitespace]"\n\n " (98..108),
),
},
},
@ -60,10 +60,10 @@ TemplateAst {
Interpolation {
prev_whitespace_content: None,
expression: VariableAccess(
"value" (112..117),
[Ident]"value" (112..117),
),
post_whitespace_content: Some(
"\n " (120..129),
[Whitespace]"\n " (120..129),
),
},
],

View file

@ -4,42 +4,42 @@ expression: parsed
---
ParsedTemplate {
tokens: [
"{{" (0..2),
" " (2..3),
"if" (3..5),
" " (5..6),
"foo" (6..9),
" " (9..10),
"}}" (10..12),
"\n " (12..25),
"{{" (25..27),
" " (27..28),
"if" (28..30),
" " (30..31),
"bar" (31..34),
" " (34..35),
"}}" (35..37),
"\n " (37..54),
"Hiii" (54..58),
"\n " (58..71),
"{{" (71..73),
" " (73..74),
"end" (74..77),
" " (77..78),
"}}" (78..80),
"\n " (80..89),
"{{" (89..91),
" " (91..92),
"end" (92..95),
" " (95..96),
"}}" (96..98),
"\n\n " (98..108),
"{{" (108..110),
"=" (110..111),
" " (111..112),
"value" (112..117),
" " (117..118),
"}}" (118..120),
"\n " (120..129),
[LeftDelim]"{{" (0..2),
[Whitespace]" " (2..3),
[ConditionalIf]"if" (3..5),
[Whitespace]" " (5..6),
[Ident]"foo" (6..9),
[Whitespace]" " (9..10),
[RightDelim]"}}" (10..12),
[Whitespace]"\n " (12..25),
[LeftDelim]"{{" (25..27),
[Whitespace]" " (27..28),
[ConditionalIf]"if" (28..30),
[Whitespace]" " (30..31),
[Ident]"bar" (31..34),
[Whitespace]" " (34..35),
[RightDelim]"}}" (35..37),
[Whitespace]"\n " (37..54),
[Content]"Hiii" (54..58),
[Whitespace]"\n " (58..71),
[LeftDelim]"{{" (71..73),
[Whitespace]" " (73..74),
[End]"end" (74..77),
[Whitespace]" " (77..78),
[RightDelim]"}}" (78..80),
[Whitespace]"\n " (80..89),
[LeftDelim]"{{" (89..91),
[Whitespace]" " (91..92),
[End]"end" (92..95),
[Whitespace]" " (95..96),
[RightDelim]"}}" (96..98),
[Whitespace]"\n\n " (98..108),
[LeftDelim]"{{" (108..110),
[WantsOutput]"=" (110..111),
[Whitespace]" " (111..112),
[Ident]"value" (112..117),
[Whitespace]" " (117..118),
[RightDelim]"}}" (118..120),
[Whitespace]"\n " (120..129),
],
}

View file

@ -254,7 +254,7 @@ pub struct TemplateToken {
impl std::fmt::Debug for TemplateToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.source())
write!(f, "[{:?}]{:?}", self.kind(), self.source())
}
}
@ -495,7 +495,7 @@ mod tests {
Ok(
ParsedTemplate {
tokens: [
"Hello There" (0..11),
[Content]"Hello There" (0..11),
],
},
)
@ -511,13 +511,13 @@ mod tests {
Ok(
ParsedTemplate {
tokens: [
"Hello" (0..5),
" " (5..6),
"{{" (6..8),
" " (8..9),
"there" (9..14),
" " (14..15),
"}}" (15..17),
[Content]"Hello" (0..5),
[Whitespace]" " (5..6),
[LeftDelim]"{{" (6..8),
[Whitespace]" " (8..9),
[Ident]"there" (9..14),
[Whitespace]" " (14..15),
[RightDelim]"}}" (15..17),
],
},
)
@ -567,29 +567,29 @@ mod tests {
Ok(
ParsedTemplate {
tokens: [
"{{" (0..2),
" " (2..3),
"if" (3..5),
" " (5..6),
"true" (6..10),
" " (10..11),
"}}" (11..13),
" " (13..14),
"Hello!" (14..20),
" " (20..21),
"{{" (21..23),
" " (23..24),
"else" (24..28),
" " (28..29),
"}}" (29..31),
" " (31..32),
"Bye" (32..35),
" " (35..36),
"{{" (36..38),
" " (38..39),
"end" (39..42),
" " (42..43),
"}}" (43..45),
[LeftDelim]"{{" (0..2),
[Whitespace]" " (2..3),
[ConditionalIf]"if" (3..5),
[Whitespace]" " (5..6),
[Literal(Bool(true))]"true" (6..10),
[Whitespace]" " (10..11),
[RightDelim]"}}" (11..13),
[Whitespace]" " (13..14),
[Content]"Hello!" (14..20),
[Whitespace]" " (20..21),
[LeftDelim]"{{" (21..23),
[Whitespace]" " (23..24),
[ConditionalElse]"else" (24..28),
[Whitespace]" " (28..29),
[RightDelim]"}}" (29..31),
[Whitespace]" " (31..32),
[Content]"Bye" (32..35),
[Whitespace]" " (35..36),
[LeftDelim]"{{" (36..38),
[Whitespace]" " (38..39),
[End]"end" (39..42),
[Whitespace]" " (42..43),
[RightDelim]"}}" (43..45),
],
},
)