Compare commits
No commits in common. "383f5431198b15a673256f386ec437f2b863e594" and "b69c659583bc79523fe4b63457c9a4f1308f6ce1" have entirely different histories.
383f543119
...
b69c659583
15 changed files with 246 additions and 269 deletions
|
|
@ -229,6 +229,7 @@ pub enum TemplateAstExpr<'input> {
|
||||||
IfConditional {
|
IfConditional {
|
||||||
if_block: Box<TemplateAstExpr<'input>>,
|
if_block: Box<TemplateAstExpr<'input>>,
|
||||||
content: Vec<TemplateAstExpr<'input>>,
|
content: Vec<TemplateAstExpr<'input>>,
|
||||||
|
end_block: Box<TemplateAstExpr<'input>>,
|
||||||
},
|
},
|
||||||
ElseConditional {
|
ElseConditional {
|
||||||
expression: Vec<TemplateAstExpr<'input>>,
|
expression: Vec<TemplateAstExpr<'input>>,
|
||||||
|
|
@ -318,10 +319,13 @@ fn parse_conditional_chain<'input>(
|
||||||
let mut chain = vec![];
|
let mut chain = vec![];
|
||||||
|
|
||||||
let (content, end_block): (Vec<_>, _) =
|
let (content, end_block): (Vec<_>, _) =
|
||||||
repeat_till(0.., parse_ast, parse_end).parse_next(input)?;
|
repeat_till(0.., parse_ast, parse_end.map(Box::new)).parse_next(input)?;
|
||||||
|
|
||||||
chain.push(TemplateAstExpr::IfConditional { if_block, content });
|
chain.push(TemplateAstExpr::IfConditional {
|
||||||
chain.push(end_block);
|
if_block,
|
||||||
|
content,
|
||||||
|
end_block,
|
||||||
|
});
|
||||||
|
|
||||||
Ok(TemplateAstExpr::ConditionalChain { chain })
|
Ok(TemplateAstExpr::ConditionalChain { chain })
|
||||||
})
|
})
|
||||||
|
|
@ -452,7 +456,7 @@ mod tests {
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hello World" (0..11),
|
"Hello World" (0..11),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
@ -471,14 +475,14 @@ mod tests {
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hello" (0..5),
|
"Hello" (0..5),
|
||||||
),
|
),
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: Some(
|
prev_whitespace_content: Some(
|
||||||
[Whitespace]" " (5..6),
|
" " (5..6),
|
||||||
),
|
),
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"world" (10..15),
|
"world" (10..15),
|
||||||
),
|
),
|
||||||
post_whitespace_content: None,
|
post_whitespace_content: None,
|
||||||
},
|
},
|
||||||
|
|
@ -504,24 +508,24 @@ mod tests {
|
||||||
if_block: Block {
|
if_block: Block {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"foo" (6..9),
|
"foo" (6..9),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]" " (12..13),
|
" " (12..13),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
content: [
|
content: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hiii" (13..17),
|
"Hiii" (13..17),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
},
|
end_block: Block {
|
||||||
Block {
|
prev_whitespace_content: Some(
|
||||||
prev_whitespace_content: Some(
|
" " (17..18),
|
||||||
[Whitespace]" " (17..18),
|
),
|
||||||
),
|
expression: EndBlock,
|
||||||
expression: EndBlock,
|
post_whitespace_content: None,
|
||||||
post_whitespace_content: None,
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
@ -600,11 +604,11 @@ mod tests {
|
||||||
insta::assert_debug_snapshot!(result, @r#"
|
insta::assert_debug_snapshot!(result, @r#"
|
||||||
(
|
(
|
||||||
[
|
[
|
||||||
[LeftDelim]"{{" (0..2),
|
"{{" (0..2),
|
||||||
[Whitespace]" " (2..3),
|
" " (2..3),
|
||||||
[Ident]"foo" (3..6),
|
"foo" (3..6),
|
||||||
[Whitespace]" " (6..7),
|
" " (6..7),
|
||||||
[RightDelim]"}}" (7..9),
|
"}}" (7..9),
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ TemplateAst {
|
||||||
if_block: Block {
|
if_block: Block {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"foo" (6..9),
|
"foo" (6..9),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n " (12..25),
|
"\n " (12..25),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
content: [
|
content: [
|
||||||
|
|
@ -23,47 +23,47 @@ TemplateAst {
|
||||||
if_block: Block {
|
if_block: Block {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"bar" (31..34),
|
"bar" (31..34),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n " (37..54),
|
"\n " (37..54),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
content: [
|
content: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hiii" (54..58),
|
"Hiii" (54..58),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
},
|
end_block: Block {
|
||||||
Block {
|
prev_whitespace_content: Some(
|
||||||
prev_whitespace_content: Some(
|
"\n " (58..71),
|
||||||
[Whitespace]"\n " (58..71),
|
),
|
||||||
),
|
expression: EndBlock,
|
||||||
expression: EndBlock,
|
post_whitespace_content: Some(
|
||||||
post_whitespace_content: Some(
|
"\n " (80..89),
|
||||||
[Whitespace]"\n " (80..89),
|
),
|
||||||
),
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
end_block: Block {
|
||||||
Block {
|
prev_whitespace_content: None,
|
||||||
prev_whitespace_content: None,
|
expression: EndBlock,
|
||||||
expression: EndBlock,
|
post_whitespace_content: Some(
|
||||||
post_whitespace_content: Some(
|
"\n\n " (98..108),
|
||||||
[Whitespace]"\n\n " (98..108),
|
),
|
||||||
),
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"value" (112..117),
|
"value" (112..117),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n " (120..129),
|
"\n " (120..129),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -4,42 +4,42 @@ expression: parsed
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[LeftDelim]"{{" (0..2),
|
"{{" (0..2),
|
||||||
[Whitespace]" " (2..3),
|
" " (2..3),
|
||||||
[ConditionalIf]"if" (3..5),
|
"if" (3..5),
|
||||||
[Whitespace]" " (5..6),
|
" " (5..6),
|
||||||
[Ident]"foo" (6..9),
|
"foo" (6..9),
|
||||||
[Whitespace]" " (9..10),
|
" " (9..10),
|
||||||
[RightDelim]"}}" (10..12),
|
"}}" (10..12),
|
||||||
[Whitespace]"\n " (12..25),
|
"\n " (12..25),
|
||||||
[LeftDelim]"{{" (25..27),
|
"{{" (25..27),
|
||||||
[Whitespace]" " (27..28),
|
" " (27..28),
|
||||||
[ConditionalIf]"if" (28..30),
|
"if" (28..30),
|
||||||
[Whitespace]" " (30..31),
|
" " (30..31),
|
||||||
[Ident]"bar" (31..34),
|
"bar" (31..34),
|
||||||
[Whitespace]" " (34..35),
|
" " (34..35),
|
||||||
[RightDelim]"}}" (35..37),
|
"}}" (35..37),
|
||||||
[Whitespace]"\n " (37..54),
|
"\n " (37..54),
|
||||||
[Content]"Hiii" (54..58),
|
"Hiii" (54..58),
|
||||||
[Whitespace]"\n " (58..71),
|
"\n " (58..71),
|
||||||
[LeftDelim]"{{" (71..73),
|
"{{" (71..73),
|
||||||
[Whitespace]" " (73..74),
|
" " (73..74),
|
||||||
[End]"end" (74..77),
|
"end" (74..77),
|
||||||
[Whitespace]" " (77..78),
|
" " (77..78),
|
||||||
[RightDelim]"}}" (78..80),
|
"}}" (78..80),
|
||||||
[Whitespace]"\n " (80..89),
|
"\n " (80..89),
|
||||||
[LeftDelim]"{{" (89..91),
|
"{{" (89..91),
|
||||||
[Whitespace]" " (91..92),
|
" " (91..92),
|
||||||
[End]"end" (92..95),
|
"end" (92..95),
|
||||||
[Whitespace]" " (95..96),
|
" " (95..96),
|
||||||
[RightDelim]"}}" (96..98),
|
"}}" (96..98),
|
||||||
[Whitespace]"\n\n " (98..108),
|
"\n\n " (98..108),
|
||||||
[LeftDelim]"{{" (108..110),
|
"{{" (108..110),
|
||||||
[WantsOutput]"=" (110..111),
|
"=" (110..111),
|
||||||
[Whitespace]" " (111..112),
|
" " (111..112),
|
||||||
[Ident]"value" (112..117),
|
"value" (112..117),
|
||||||
[Whitespace]" " (117..118),
|
" " (117..118),
|
||||||
[RightDelim]"}}" (118..120),
|
"}}" (118..120),
|
||||||
[Whitespace]"\n " (120..129),
|
"\n " (120..129),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ fn emit_ast_expr(
|
||||||
let Some(TemplateAstExpr::IfConditional {
|
let Some(TemplateAstExpr::IfConditional {
|
||||||
if_block: expression,
|
if_block: expression,
|
||||||
content,
|
content,
|
||||||
|
end_block,
|
||||||
}) = chain.next()
|
}) = chain.next()
|
||||||
else {
|
else {
|
||||||
unreachable!("First element in conditional chain should be an IfConditional");
|
unreachable!("First element in conditional chain should be an IfConditional");
|
||||||
|
|
@ -132,13 +133,13 @@ fn emit_ast_expr(
|
||||||
emit_ast_expr(machine, eval, ast);
|
emit_ast_expr(machine, eval, ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(TemplateAstExpr::Block {
|
let TemplateAstExpr::Block {
|
||||||
prev_whitespace_content,
|
prev_whitespace_content,
|
||||||
post_whitespace_content,
|
post_whitespace_content,
|
||||||
..
|
..
|
||||||
}) = chain.last()
|
} = end_block.as_ref()
|
||||||
else {
|
else {
|
||||||
unreachable!("The end of an IfConditional must be a End Block");
|
unreachable!("The end of an IfConditional must be a Block");
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = prev_whitespace_content {
|
if let Some(ws) = prev_whitespace_content {
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,6 @@ pub enum TokenKind {
|
||||||
Whitespace,
|
Whitespace,
|
||||||
Invalid,
|
Invalid,
|
||||||
ConditionalIf,
|
ConditionalIf,
|
||||||
ConditionalElse,
|
|
||||||
End,
|
End,
|
||||||
Literal(TokenLiteral),
|
Literal(TokenLiteral),
|
||||||
}
|
}
|
||||||
|
|
@ -254,7 +253,7 @@ pub struct TemplateToken {
|
||||||
|
|
||||||
impl std::fmt::Debug for TemplateToken {
|
impl std::fmt::Debug for TemplateToken {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "[{:?}]{:?}", self.kind(), self.source())
|
write!(f, "{:?}", self.source())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,7 +290,6 @@ impl TemplateToken {
|
||||||
whitespace => TokenKind::Whitespace,
|
whitespace => TokenKind::Whitespace,
|
||||||
invalid => TokenKind::Invalid,
|
invalid => TokenKind::Invalid,
|
||||||
conditional_if => TokenKind::ConditionalIf,
|
conditional_if => TokenKind::ConditionalIf,
|
||||||
conditional_else => TokenKind::ConditionalElse,
|
|
||||||
end => TokenKind::End,
|
end => TokenKind::End,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,7 +344,7 @@ fn parse_interpolate<'input>(input: &mut Input<'input>) -> PResult<'input, Vec<T
|
||||||
let left_delim = "{{".map(TemplateToken::left_delim).parse_next(input)?;
|
let left_delim = "{{".map(TemplateToken::left_delim).parse_next(input)?;
|
||||||
let wants_output = opt("=".map(TemplateToken::wants_output)).parse_next(input)?;
|
let wants_output = opt("=".map(TemplateToken::wants_output)).parse_next(input)?;
|
||||||
|
|
||||||
let get_tokens = repeat_till(1.., parse_block_token, peek("}}"));
|
let get_tokens = repeat_till(1.., parse_interpolate_token, peek("}}"));
|
||||||
let recover = take_until(0.., "}}").void();
|
let recover = take_until(0.., "}}").void();
|
||||||
|
|
||||||
let (inside_tokens, _): (Vec<_>, _) = get_tokens
|
let (inside_tokens, _): (Vec<_>, _) = get_tokens
|
||||||
|
|
@ -371,14 +369,13 @@ fn parse_interpolate<'input>(input: &mut Input<'input>) -> PResult<'input, Vec<T
|
||||||
Ok(tokens)
|
Ok(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_block_token<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
fn parse_interpolate_token<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
||||||
trace(
|
trace(
|
||||||
"parse_block_token",
|
"parse_interpolate_token",
|
||||||
alt((
|
alt((
|
||||||
parse_ident,
|
parse_ident,
|
||||||
parse_literal,
|
parse_literal,
|
||||||
parse_condition_if,
|
parse_condition,
|
||||||
parse_condition_else,
|
|
||||||
parse_end,
|
parse_end,
|
||||||
parse_whitespace,
|
parse_whitespace,
|
||||||
)),
|
)),
|
||||||
|
|
@ -388,7 +385,7 @@ fn parse_block_token<'input>(input: &mut Input<'input>) -> PResult<'input, Templ
|
||||||
|
|
||||||
fn parse_literal<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
fn parse_literal<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
||||||
trace(
|
trace(
|
||||||
"parse_literal",
|
"parse_condition",
|
||||||
alt((parse_boolean,))
|
alt((parse_boolean,))
|
||||||
.with_taken()
|
.with_taken()
|
||||||
.map(|(lit, span)| TemplateToken::literal(lit, span)),
|
.map(|(lit, span)| TemplateToken::literal(lit, span)),
|
||||||
|
|
@ -404,24 +401,12 @@ fn parse_boolean<'input>(input: &mut Input<'input>) -> PResult<'input, TokenLite
|
||||||
.parse_next(input)
|
.parse_next(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_condition_if<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
fn parse_condition<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
||||||
trace(
|
trace("parse_condition", "if".map(TemplateToken::conditional_if)).parse_next(input)
|
||||||
"parse_condition_if",
|
|
||||||
"if".map(TemplateToken::conditional_if),
|
|
||||||
)
|
|
||||||
.parse_next(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_condition_else<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
|
||||||
trace(
|
|
||||||
"parse_condition_else",
|
|
||||||
"else".map(TemplateToken::conditional_else),
|
|
||||||
)
|
|
||||||
.parse_next(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_end<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
fn parse_end<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
||||||
trace("parse_end", "end".map(TemplateToken::end)).parse_next(input)
|
trace("parse_condition", "end".map(TemplateToken::end)).parse_next(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_whitespace<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
fn parse_whitespace<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateToken> {
|
||||||
|
|
@ -451,14 +436,9 @@ fn parse_ident<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateTok
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ident<'input>(input: &mut Input<'input>) -> PResult<'input, NomoInput> {
|
fn ident<'input>(input: &mut Input<'input>) -> PResult<'input, NomoInput> {
|
||||||
peek(not(alt((
|
peek(not(alt((parse_literal, parse_condition, parse_end))))
|
||||||
parse_literal,
|
.context(ParseError::ctx().msg("Expected an ident, but found a literal instead"))
|
||||||
parse_condition_if,
|
.parse_next(input)?;
|
||||||
parse_condition_else,
|
|
||||||
parse_end,
|
|
||||||
))))
|
|
||||||
.context(ParseError::ctx().msg("Expected an ident, but found a literal instead"))
|
|
||||||
.parse_next(input)?;
|
|
||||||
|
|
||||||
take_while(1.., |c: char| c.is_alphanumeric() || "_".contains(c)).parse_next(input)
|
take_while(1.., |c: char| c.is_alphanumeric() || "_".contains(c)).parse_next(input)
|
||||||
}
|
}
|
||||||
|
|
@ -495,7 +475,7 @@ mod tests {
|
||||||
Ok(
|
Ok(
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[Content]"Hello There" (0..11),
|
"Hello There" (0..11),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -511,13 +491,13 @@ mod tests {
|
||||||
Ok(
|
Ok(
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[Content]"Hello" (0..5),
|
"Hello" (0..5),
|
||||||
[Whitespace]" " (5..6),
|
" " (5..6),
|
||||||
[LeftDelim]"{{" (6..8),
|
"{{" (6..8),
|
||||||
[Whitespace]" " (8..9),
|
" " (8..9),
|
||||||
[Ident]"there" (9..14),
|
"there" (9..14),
|
||||||
[Whitespace]" " (14..15),
|
" " (14..15),
|
||||||
[RightDelim]"}}" (15..17),
|
"}}" (15..17),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -560,36 +540,28 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_simple_condition() {
|
fn parse_simple_condition() {
|
||||||
let input = "{{ if true }} Hello! {{ else }} Bye {{ end }}";
|
let input = "{{ if true }} Hello! {{ end }}";
|
||||||
let output = parse(input.into());
|
let output = parse(input.into());
|
||||||
|
|
||||||
insta::assert_debug_snapshot!(output, @r#"
|
insta::assert_debug_snapshot!(output, @r#"
|
||||||
Ok(
|
Ok(
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[LeftDelim]"{{" (0..2),
|
"{{" (0..2),
|
||||||
[Whitespace]" " (2..3),
|
" " (2..3),
|
||||||
[ConditionalIf]"if" (3..5),
|
"if" (3..5),
|
||||||
[Whitespace]" " (5..6),
|
" " (5..6),
|
||||||
[Literal(Bool(true))]"true" (6..10),
|
"true" (6..10),
|
||||||
[Whitespace]" " (10..11),
|
" " (10..11),
|
||||||
[RightDelim]"}}" (11..13),
|
"}}" (11..13),
|
||||||
[Whitespace]" " (13..14),
|
" " (13..14),
|
||||||
[Content]"Hello!" (14..20),
|
"Hello!" (14..20),
|
||||||
[Whitespace]" " (20..21),
|
" " (20..21),
|
||||||
[LeftDelim]"{{" (21..23),
|
"{{" (21..23),
|
||||||
[Whitespace]" " (23..24),
|
" " (23..24),
|
||||||
[ConditionalElse]"else" (24..28),
|
"end" (24..27),
|
||||||
[Whitespace]" " (28..29),
|
" " (27..28),
|
||||||
[RightDelim]"}}" (29..31),
|
"}}" (28..30),
|
||||||
[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),
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,27 @@ input_file: tests/cases/condition.nomo
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[LeftDelim]"{{" (0..2),
|
"{{" (0..2),
|
||||||
[Whitespace]" " (2..3),
|
" " (2..3),
|
||||||
[ConditionalIf]"if" (3..5),
|
"if" (3..5),
|
||||||
[Whitespace]" " (5..6),
|
" " (5..6),
|
||||||
[Ident]"test" (6..10),
|
"test" (6..10),
|
||||||
[Whitespace]" " (10..11),
|
" " (10..11),
|
||||||
[RightDelim]"}}" (11..13),
|
"}}" (11..13),
|
||||||
[Whitespace]"\n " (13..18),
|
"\n " (13..18),
|
||||||
[Content]"Hello World!" (18..30),
|
"Hello World!" (18..30),
|
||||||
[Whitespace]"\n" (30..31),
|
"\n" (30..31),
|
||||||
[LeftDelim]"{{" (31..33),
|
"{{" (31..33),
|
||||||
[Whitespace]" " (33..34),
|
" " (33..34),
|
||||||
[End]"end" (34..37),
|
"end" (34..37),
|
||||||
[Whitespace]" " (37..38),
|
" " (37..38),
|
||||||
[RightDelim]"}}" (38..40),
|
"}}" (38..40),
|
||||||
[Whitespace]"\n\n" (40..42),
|
"\n\n" (40..42),
|
||||||
[LeftDelim]"{{" (42..44),
|
"{{" (42..44),
|
||||||
[WantsOutput]"=" (44..45),
|
"=" (44..45),
|
||||||
[Whitespace]" " (45..46),
|
" " (45..46),
|
||||||
[Ident]"stuff" (46..51),
|
"stuff" (46..51),
|
||||||
[Whitespace]" " (51..52),
|
" " (51..52),
|
||||||
[RightDelim]"}}" (52..54),
|
"}}" (52..54),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,46 +5,46 @@ input_file: tests/cases/identifiers.nomo
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[LeftDelim]"{{" (0..2),
|
"{{" (0..2),
|
||||||
[WantsOutput]"=" (2..3),
|
"=" (2..3),
|
||||||
[Whitespace]" " (3..4),
|
" " (3..4),
|
||||||
[Ident]"_name" (4..9),
|
"_name" (4..9),
|
||||||
[Whitespace]" " (9..10),
|
" " (9..10),
|
||||||
[RightDelim]"}}" (10..12),
|
"}}" (10..12),
|
||||||
[Whitespace]"\n" (12..13),
|
"\n" (12..13),
|
||||||
[LeftDelim]"{{" (13..15),
|
"{{" (13..15),
|
||||||
[WantsOutput]"=" (15..16),
|
"=" (15..16),
|
||||||
[Whitespace]" " (16..17),
|
" " (16..17),
|
||||||
[Ident]"a_name" (17..23),
|
"a_name" (17..23),
|
||||||
[Whitespace]" " (23..24),
|
" " (23..24),
|
||||||
[RightDelim]"}}" (24..26),
|
"}}" (24..26),
|
||||||
[Whitespace]"\n" (26..27),
|
"\n" (26..27),
|
||||||
[LeftDelim]"{{" (27..29),
|
"{{" (27..29),
|
||||||
[WantsOutput]"=" (29..30),
|
"=" (29..30),
|
||||||
[Whitespace]" " (30..31),
|
" " (30..31),
|
||||||
[Ident]"1name" (31..36),
|
"1name" (31..36),
|
||||||
[Whitespace]" " (36..37),
|
" " (36..37),
|
||||||
[RightDelim]"}}" (37..39),
|
"}}" (37..39),
|
||||||
[Whitespace]"\n" (39..40),
|
"\n" (39..40),
|
||||||
[LeftDelim]"{{" (40..42),
|
"{{" (40..42),
|
||||||
[WantsOutput]"=" (42..43),
|
"=" (42..43),
|
||||||
[Whitespace]" " (43..44),
|
" " (43..44),
|
||||||
[Ident]"_name1" (44..50),
|
"_name1" (44..50),
|
||||||
[Whitespace]" " (50..51),
|
" " (50..51),
|
||||||
[RightDelim]"}}" (51..53),
|
"}}" (51..53),
|
||||||
[Whitespace]"\n" (53..54),
|
"\n" (53..54),
|
||||||
[LeftDelim]"{{" (54..56),
|
"{{" (54..56),
|
||||||
[WantsOutput]"=" (56..57),
|
"=" (56..57),
|
||||||
[Whitespace]" " (57..58),
|
" " (57..58),
|
||||||
[Ident]"_namE" (58..63),
|
"_namE" (58..63),
|
||||||
[Whitespace]" " (63..64),
|
" " (63..64),
|
||||||
[RightDelim]"}}" (64..66),
|
"}}" (64..66),
|
||||||
[Whitespace]"\n" (66..67),
|
"\n" (66..67),
|
||||||
[LeftDelim]"{{" (67..69),
|
"{{" (67..69),
|
||||||
[WantsOutput]"=" (69..70),
|
"=" (69..70),
|
||||||
[Whitespace]" " (70..71),
|
" " (70..71),
|
||||||
[Ident]"name1" (71..76),
|
"name1" (71..76),
|
||||||
[Whitespace]" " (76..77),
|
" " (76..77),
|
||||||
[RightDelim]"}}" (77..79),
|
"}}" (77..79),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ input_file: tests/cases/interpolation.nomo
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[Content]"Hello! I'm" (0..10),
|
"Hello! I'm" (0..10),
|
||||||
[Whitespace]" " (10..11),
|
" " (10..11),
|
||||||
[LeftDelim]"{{" (11..13),
|
"{{" (11..13),
|
||||||
[WantsOutput]"=" (13..14),
|
"=" (13..14),
|
||||||
[Whitespace]" " (14..15),
|
" " (14..15),
|
||||||
[Ident]"name" (15..19),
|
"name" (15..19),
|
||||||
[Whitespace]" " (19..20),
|
" " (19..20),
|
||||||
[RightDelim]"}}" (20..22),
|
"}}" (20..22),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,20 @@ input_file: tests/cases/multiple.nomo
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[Content]"Hi there! My name is" (0..20),
|
"Hi there! My name is" (0..20),
|
||||||
[Whitespace]" " (20..21),
|
" " (20..21),
|
||||||
[LeftDelim]"{{" (21..23),
|
"{{" (21..23),
|
||||||
[WantsOutput]"=" (23..24),
|
"=" (23..24),
|
||||||
[Whitespace]" " (24..25),
|
" " (24..25),
|
||||||
[Ident]"name" (25..29),
|
"name" (25..29),
|
||||||
[Whitespace]" " (29..30),
|
" " (29..30),
|
||||||
[RightDelim]"}}" (30..32),
|
"}}" (30..32),
|
||||||
[Whitespace]" " (32..33),
|
" " (32..33),
|
||||||
[LeftDelim]"{{" (33..35),
|
"{{" (33..35),
|
||||||
[WantsOutput]"=" (35..36),
|
"=" (35..36),
|
||||||
[Whitespace]" " (36..37),
|
" " (36..37),
|
||||||
[Ident]"lastname" (37..45),
|
"lastname" (37..45),
|
||||||
[Whitespace]" " (45..46),
|
" " (45..46),
|
||||||
[RightDelim]"}}" (46..48),
|
"}}" (46..48),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ input_file: tests/cases/simple.nomo
|
||||||
---
|
---
|
||||||
ParsedTemplate {
|
ParsedTemplate {
|
||||||
tokens: [
|
tokens: [
|
||||||
[Content]"Hello World!" (0..12),
|
"Hello World!" (0..12),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,33 +11,33 @@ TemplateAst {
|
||||||
if_block: Block {
|
if_block: Block {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"test" (6..10),
|
"test" (6..10),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n " (13..18),
|
"\n " (13..18),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
content: [
|
content: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hello World!" (18..30),
|
"Hello World!" (18..30),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
},
|
end_block: Block {
|
||||||
Block {
|
prev_whitespace_content: Some(
|
||||||
prev_whitespace_content: Some(
|
"\n" (30..31),
|
||||||
[Whitespace]"\n" (30..31),
|
),
|
||||||
),
|
expression: EndBlock,
|
||||||
expression: EndBlock,
|
post_whitespace_content: Some(
|
||||||
post_whitespace_content: Some(
|
"\n\n" (40..42),
|
||||||
[Whitespace]"\n\n" (40..42),
|
),
|
||||||
),
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"stuff" (46..51),
|
"stuff" (46..51),
|
||||||
),
|
),
|
||||||
post_whitespace_content: None,
|
post_whitespace_content: None,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -8,52 +8,52 @@ TemplateAst {
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"_name" (4..9),
|
"_name" (4..9),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n" (12..13),
|
"\n" (12..13),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"a_name" (17..23),
|
"a_name" (17..23),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n" (26..27),
|
"\n" (26..27),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"1name" (31..36),
|
"1name" (31..36),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n" (39..40),
|
"\n" (39..40),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"_name1" (44..50),
|
"_name1" (44..50),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n" (53..54),
|
"\n" (53..54),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"_namE" (58..63),
|
"_namE" (58..63),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]"\n" (66..67),
|
"\n" (66..67),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"name1" (71..76),
|
"name1" (71..76),
|
||||||
),
|
),
|
||||||
post_whitespace_content: None,
|
post_whitespace_content: None,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@ input_file: tests/cases/interpolation.nomo
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hello! I'm" (0..10),
|
"Hello! I'm" (0..10),
|
||||||
),
|
),
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: Some(
|
prev_whitespace_content: Some(
|
||||||
[Whitespace]" " (10..11),
|
" " (10..11),
|
||||||
),
|
),
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"name" (15..19),
|
"name" (15..19),
|
||||||
),
|
),
|
||||||
post_whitespace_content: None,
|
post_whitespace_content: None,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,23 @@ input_file: tests/cases/multiple.nomo
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hi there! My name is" (0..20),
|
"Hi there! My name is" (0..20),
|
||||||
),
|
),
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: Some(
|
prev_whitespace_content: Some(
|
||||||
[Whitespace]" " (20..21),
|
" " (20..21),
|
||||||
),
|
),
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"name" (25..29),
|
"name" (25..29),
|
||||||
),
|
),
|
||||||
post_whitespace_content: Some(
|
post_whitespace_content: Some(
|
||||||
[Whitespace]" " (32..33),
|
" " (32..33),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Interpolation {
|
Interpolation {
|
||||||
prev_whitespace_content: None,
|
prev_whitespace_content: None,
|
||||||
expression: VariableAccess(
|
expression: VariableAccess(
|
||||||
[Ident]"lastname" (37..45),
|
"lastname" (37..45),
|
||||||
),
|
),
|
||||||
post_whitespace_content: None,
|
post_whitespace_content: None,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ input_file: tests/cases/simple.nomo
|
||||||
TemplateAst {
|
TemplateAst {
|
||||||
root: [
|
root: [
|
||||||
StaticContent(
|
StaticContent(
|
||||||
[Content]"Hello World!" (0..12),
|
"Hello World!" (0..12),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue