From 3000d98a04882655cabe71dd590716d73cd892da Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 13 Feb 2017 21:51:20 +0100 Subject: Establish expression parser hierarchy --- askama/src/parser.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/askama/src/parser.rs b/askama/src/parser.rs index 5f14482..2654c9b 100644 --- a/askama/src/parser.rs +++ b/askama/src/parser.rs @@ -105,22 +105,23 @@ fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr> { IResult::Done(left, expr) } -named!(expr_compare, do_parse!( - left: expr_filtered >> - op: ws!(alt!( - tag_s!("==") | tag_s!("!=") | - tag_s!(">=") | tag_s!(">") | - tag_s!("<=") | tag_s!("<") - )) >> - right: expr_filtered >> - (Expr::BinOp(str::from_utf8(op).unwrap(), - Box::new(left), Box::new(right))) +named!(expr_single, alt!( + expr_filtered | + expr_str_lit )); named!(expr_any, alt!( - expr_compare | - expr_filtered | - expr_str_lit + do_parse!( + left: expr_single >> + op: ws!(alt!( + tag_s!("==") | tag_s!("!=") | + tag_s!(">=") | 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_node, do_parse!( -- cgit