diff options
author | vallentin <mail@vallentin.dev> | 2021-01-05 15:30:37 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-01-05 16:15:16 +0100 |
commit | a3633879e302f5fd9034a17b9520fdf8c1b18ff9 (patch) | |
tree | a96a16cea3fdfe12cb6cb089a0c023bb21301b7a /askama_shared/src/parser.rs | |
parent | c29ecd68714bddf5e27a9e347c902faa23b2a545 (diff) | |
download | askama-a3633879e302f5fd9034a17b9520fdf8c1b18ff9.tar.gz askama-a3633879e302f5fd9034a17b9520fdf8c1b18ff9.tar.bz2 askama-a3633879e302f5fd9034a17b9520fdf8c1b18ff9.zip |
Fixed precedence of filters and unary operators (fixes #424)
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r-- | askama_shared/src/parser.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 275c92b..58f29f6 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -539,7 +539,7 @@ fn filter(i: &[u8]) -> IResult<&[u8], (&str, Option<Vec<Expr>>)> { } fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr> { - let (i, (obj, filters)) = tuple((expr_index, many0(filter)))(i)?; + let (i, (obj, filters)) = tuple((expr_unary, many0(filter)))(i)?; let mut res = obj; for (fname, args) in filters { @@ -557,7 +557,7 @@ fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr> { } fn expr_unary(i: &[u8]) -> IResult<&[u8], Expr> { - let (i, (op, expr)) = tuple((opt(alt((ws(tag("!")), ws(tag("-"))))), expr_filtered))(i)?; + let (i, (op, expr)) = tuple((opt(alt((ws(tag("!")), ws(tag("-"))))), expr_index))(i)?; Ok(( i, match op { @@ -605,7 +605,7 @@ macro_rules! expr_prec_layer { } } -expr_prec_layer!(expr_muldivmod, expr_unary, "*", "/", "%"); +expr_prec_layer!(expr_muldivmod, expr_filtered, "*", "/", "%"); expr_prec_layer!(expr_addsub, expr_muldivmod, "+", "-"); expr_prec_layer!(expr_shifts, expr_addsub, ">>", "<<"); expr_prec_layer!(expr_band, expr_shifts, "&"); |