diff options
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r-- | askama_shared/src/parser.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index f429628..63cea0c 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -63,6 +63,7 @@ pub enum Expr<'a> { Group(Box<Expr<'a>>), Call(Box<Expr<'a>>, Vec<Expr<'a>>), RustMacro(&'a str, &'a str), + Try(Box<Expr<'a>>), } impl Expr<'_> { @@ -510,6 +511,7 @@ enum Suffix<'a> { Attr(&'a str), Index(Expr<'a>), Call(Vec<Expr<'a>>), + Try, } fn expr_attr(i: &str) -> IResult<&str, Suffix<'_>> { @@ -533,6 +535,10 @@ fn expr_call(i: &str) -> IResult<&str, Suffix<'_>> { map(arguments, Suffix::Call)(i) } +fn expr_try(i: &str) -> IResult<&str, Suffix<'_>> { + map(preceded(take_till(not_ws), char('?')), |_| Suffix::Try)(i) +} + fn filter(i: &str) -> IResult<&str, (&str, Option<Vec<Expr<'_>>>)> { let (i, (_, fname, args)) = tuple((char('|'), ws(identifier), opt(arguments)))(i)?; Ok((i, (fname, args))) @@ -567,12 +573,13 @@ fn expr_prefix(i: &str) -> IResult<&str, Expr<'_>> { fn expr_suffix(i: &str) -> IResult<&str, Expr<'_>> { let (mut i, mut expr) = expr_single(i)?; loop { - let (j, suffix) = opt(alt((expr_attr, expr_index, expr_call)))(i)?; + let (j, suffix) = opt(alt((expr_attr, expr_index, expr_call, expr_try)))(i)?; i = j; match suffix { Some(Suffix::Attr(attr)) => expr = Expr::Attr(expr.into(), attr), Some(Suffix::Index(index)) => expr = Expr::Index(expr.into(), index.into()), Some(Suffix::Call(args)) => expr = Expr::Call(expr.into(), args), + Some(Suffix::Try) => expr = Expr::Try(expr.into()), None => break, } } |