Allow trimming of whitespace

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-09 13:24:40 +01:00
parent 587cfdea53
commit 59f92e31fe
8 changed files with 243 additions and 9 deletions

View file

@ -0,0 +1,34 @@
---
source: tests/file_tests.rs
expression: parsed
input_file: tests/cases/trim_whitespace.nomo
---
ParsedTemplate {
tokens: [
[LeftDelim]"{{" (0..2),
[Whitespace]" " (2..3),
[ConditionalIf]"if" (3..5),
[Whitespace]" " (5..6),
[Ident]"test" (6..10),
[Whitespace]" " (10..11),
[TrimWhitespace]"-" (11..12),
[RightDelim]"}}" (12..14),
[Whitespace]"\n " (14..19),
[Content]"Hello" (19..24),
[Whitespace]" " (24..25),
[LeftDelim]"{{" (25..27),
[WantsOutput]"=" (27..28),
[Whitespace]" " (28..29),
[Ident]"stuff" (29..34),
[Whitespace]" " (34..35),
[TrimWhitespace]"-" (35..36),
[RightDelim]"}}" (36..38),
[Whitespace]"\n" (38..39),
[LeftDelim]"{{" (39..41),
[TrimWhitespace]"-" (41..42),
[Whitespace]" " (42..43),
[End]"end" (43..46),
[Whitespace]" " (46..47),
[RightDelim]"}}" (47..49),
],
}

View file

@ -0,0 +1,43 @@
---
source: tests/file_tests.rs
expression: ast
input_file: tests/cases/trim_whitespace.nomo
---
TemplateAst {
root: [
ConditionalChain {
chain: [
Block {
prev_whitespace_content: None,
expression: IfConditional {
expression: VariableAccess(
[Ident]"test" (6..10),
),
},
post_whitespace_content: None,
},
ConditionalContent {
content: [
StaticContent(
[Content]"Hello" (19..24),
),
Interpolation {
prev_whitespace_content: Some(
[Whitespace]" " (24..25),
),
expression: VariableAccess(
[Ident]"stuff" (29..34),
),
post_whitespace_content: None,
},
],
},
Block {
prev_whitespace_content: None,
expression: EndBlock,
post_whitespace_content: None,
},
],
},
],
}

View file

@ -0,0 +1,39 @@
---
source: tests/file_tests.rs
expression: emit
input_file: tests/cases/trim_whitespace.nomo
---
[
LoadFromContextToSlot {
name: "test" (6..10),
slot: VariableSlot {
index: 0,
},
},
JumpIfNotTrue {
emit_slot: VariableSlot {
index: 0,
},
jump: 5,
},
AppendContent {
content: "Hello" (19..24),
},
AppendContent {
content: " " (24..25),
},
LoadFromContextToSlot {
name: "stuff" (29..34),
slot: VariableSlot {
index: 1,
},
},
EmitFromSlot {
slot: VariableSlot {
index: 1,
},
},
Jump {
jump: 0,
},
]

View file

@ -0,0 +1,6 @@
---
source: tests/file_tests.rs
expression: output
input_file: tests/cases/trim_whitespace.nomo
---
"Hello Hemera"

View file

@ -0,0 +1,8 @@
{
"test": true,
"stuff": "Hemera"
}
---
{{ if test -}}
Hello {{= stuff -}}
{{- end }}