aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-13 21:40:16 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-13 21:40:16 +0100
commit6b68856b284e8bd7f2b1b316b76677b13ec93e60 (patch)
tree3c56a7e7a90d8922eb95b7f24d377fede2d79fd1
parent66a1a06df12367260343da43aadcb7807c812ac2 (diff)
downloadaskama-6b68856b284e8bd7f2b1b316b76677b13ec93e60.tar.gz
askama-6b68856b284e8bd7f2b1b316b76677b13ec93e60.tar.bz2
askama-6b68856b284e8bd7f2b1b316b76677b13ec93e60.zip
Generically represent binary operators in parse tree
Diffstat (limited to '')
-rw-r--r--askama/src/generator.rs6
-rw-r--r--askama/src/parser.rs6
2 files changed, 6 insertions, 6 deletions
diff --git a/askama/src/generator.rs b/askama/src/generator.rs
index 66a266c..d8018c6 100644
--- a/askama/src/generator.rs
+++ b/askama/src/generator.rs
@@ -95,7 +95,7 @@ impl<'a> Generator<'a> {
self.write(")");
}
- fn visit_compare(&mut self, op: &str, left: &Expr, right: &Expr) {
+ fn visit_binop(&mut self, op: &str, left: &Expr, right: &Expr) {
self.visit_expr(left);
self.write(&format!(" {} ", op));
self.visit_expr(right);
@@ -106,8 +106,8 @@ impl<'a> Generator<'a> {
Expr::StrLit(s) => self.visit_str_lit(s),
Expr::Var(s) => self.visit_var(s),
Expr::Filter(name, ref val) => self.visit_filter(name, val),
- Expr::Compare(op, ref left, ref right) =>
- self.visit_compare(op, left, right),
+ Expr::BinOp(op, ref left, ref right) =>
+ self.visit_binop(op, left, right),
}
}
diff --git a/askama/src/parser.rs b/askama/src/parser.rs
index 8265213..5f14482 100644
--- a/askama/src/parser.rs
+++ b/askama/src/parser.rs
@@ -5,7 +5,7 @@ pub enum Expr<'a> {
StrLit(&'a str),
Var(&'a str),
Filter(&'a str, Box<Expr<'a>>),
- Compare(&'a str, Box<Expr<'a>>, Box<Expr<'a>>),
+ BinOp(&'a str, Box<Expr<'a>>, Box<Expr<'a>>),
}
pub enum Target<'a> {
@@ -113,8 +113,8 @@ named!(expr_compare<Expr>, do_parse!(
tag_s!("<=") | tag_s!("<")
)) >>
right: expr_filtered >>
- (Expr::Compare(str::from_utf8(op).unwrap(),
- Box::new(left), Box::new(right)))
+ (Expr::BinOp(str::from_utf8(op).unwrap(),
+ Box::new(left), Box::new(right)))
));
named!(expr_any<Expr>, alt!(