diff options
-rw-r--r-- | askama/src/parser.rs | 16 | ||||
-rw-r--r-- | testing/templates/operators.html | 9 | ||||
-rw-r--r-- | testing/tests/operators.rs | 2 |
3 files changed, 23 insertions, 4 deletions
diff --git a/askama/src/parser.rs b/askama/src/parser.rs index 2654c9b..127d8d2 100644 --- a/askama/src/parser.rs +++ b/askama/src/parser.rs @@ -110,18 +110,28 @@ named!(expr_single<Expr>, alt!( expr_str_lit )); -named!(expr_any<Expr>, alt!( +named!(expr_muldivmod<Expr>, alt!( do_parse!( left: expr_single >> + op: ws!(alt!(tag_s!("*") | tag_s!("/") | tag_s!("%"))) >> + right: expr_single >> + (Expr::BinOp(str::from_utf8(op).unwrap(), + Box::new(left), Box::new(right))) + ) | expr_single +)); + +named!(expr_any<Expr>, alt!( + do_parse!( + left: expr_muldivmod >> op: ws!(alt!( tag_s!("==") | tag_s!("!=") | tag_s!(">=") | tag_s!(">") | tag_s!("<=") | tag_s!("<") )) >> - right: expr_single >> + right: expr_muldivmod >> (Expr::BinOp(str::from_utf8(op).unwrap(), Box::new(left), Box::new(right))) - ) | expr_single + ) | expr_muldivmod )); named!(expr_node<Node>, do_parse!( diff --git a/testing/templates/operators.html b/testing/templates/operators.html index ea22546..020126b 100644 --- a/testing/templates/operators.html +++ b/testing/templates/operators.html @@ -46,3 +46,12 @@ {%- else -%} f {%- endif %} +{% if a * c > b -%} + mul +{%- endif %} +{% if c / c == a -%} + div +{%- endif %} +{% if a % c == b -%} + mod +{%- endif %} diff --git a/testing/tests/operators.rs b/testing/tests/operators.rs index 0154118..240fd52 100644 --- a/testing/tests/operators.rs +++ b/testing/tests/operators.rs @@ -15,5 +15,5 @@ struct OperatorsTemplate { #[test] fn test_operators() { let t = OperatorsTemplate { a: 1, b: 1, c: 2 }; - assert_eq!(t.render(), "tf\ntf\ntf\ntf\ntf\ntf\n"); + assert_eq!(t.render(), "tf\ntf\ntf\ntf\ntf\ntf\nmul\ndiv\nmod\n"); } |