Parse conditional access
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
beac224f5b
commit
9b87e7089f
3 changed files with 41 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ use thiserror::Error;
|
|||
use winnow::Parser;
|
||||
use winnow::RecoverableParser;
|
||||
use winnow::combinator::Infix::Left;
|
||||
use winnow::combinator::Postfix;
|
||||
use winnow::combinator::alt;
|
||||
use winnow::combinator::cut_err;
|
||||
use winnow::combinator::delimited;
|
||||
|
|
@ -249,6 +250,7 @@ pub enum TemplateAstExpr<'input> {
|
|||
value_expression: Box<TemplateAstExpr<'input>>,
|
||||
},
|
||||
ForElse,
|
||||
ConditionalAccess(TemplateToken),
|
||||
VariableAccess(TemplateToken),
|
||||
IfConditional {
|
||||
expression: Box<TemplateAstExpr<'input>>,
|
||||
|
|
@ -709,6 +711,16 @@ fn parse_expression<'input>(
|
|||
Left Lesser => 15,
|
||||
Left LesserOrEqual => 15,
|
||||
]
|
||||
}).postfix(dispatch! { surrounded(ws, parse_operator);
|
||||
TokenOperator::QuestionMark => Postfix(22, |input, rhs| {
|
||||
match rhs {
|
||||
TemplateAstExpr::VariableAccess(access) => Ok(TemplateAstExpr::ConditionalAccess(access)),
|
||||
_ => Err(AstError::from_input(input)),
|
||||
}
|
||||
|
||||
|
||||
}),
|
||||
_ => fail
|
||||
}),
|
||||
)
|
||||
.parse_next(input)
|
||||
|
|
@ -1048,4 +1060,15 @@ mod tests {
|
|||
|
||||
insta::assert_debug_snapshot!(ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_conditional_access() {
|
||||
let input = "{{= foo? }}";
|
||||
|
||||
let parsed = crate::lexer::parse(input.into()).unwrap();
|
||||
|
||||
let ast = panic_pretty(input, parse(parsed.tokens()));
|
||||
|
||||
insta::assert_debug_snapshot!(ast);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue