aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-13 21:51:20 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-13 21:51:20 +0100
commit3000d98a04882655cabe71dd590716d73cd892da (patch)
treec695ef3444498062811c832b0bf4b27dc3ce1a29
parent6b68856b284e8bd7f2b1b316b76677b13ec93e60 (diff)
downloadaskama-3000d98a04882655cabe71dd590716d73cd892da.tar.gz
askama-3000d98a04882655cabe71dd590716d73cd892da.tar.bz2
askama-3000d98a04882655cabe71dd590716d73cd892da.zip
Establish expression parser hierarchy
Diffstat (limited to '')
-rw-r--r--askama/src/parser.rs27
1 files 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<Expr>, 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<Expr>, alt!(
+ expr_filtered |
+ expr_str_lit
));
named!(expr_any<Expr>, 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<Node>, do_parse!(