diff options
Diffstat (limited to '')
-rw-r--r-- | askama/src/generator.rs | 14 | ||||
-rw-r--r-- | askama/src/parser.rs | 8 |
2 files changed, 21 insertions, 1 deletions
diff --git a/askama/src/generator.rs b/askama/src/generator.rs index 40b6523..895ec25 100644 --- a/askama/src/generator.rs +++ b/askama/src/generator.rs @@ -146,6 +146,18 @@ impl<'a> Generator<'a> { self.visit_expr(right); } + fn visit_call(&mut self, obj: &Expr, method: &str, args: &[Expr]) { + self.visit_expr(obj); + self.write(&format!(".{}(", method)); + for (i, arg) in args.iter().enumerate() { + if i > 0 { + self.write(", "); + } + self.visit_expr(arg); + } + self.write(")"); + } + fn visit_expr(&mut self, expr: &Expr) { match *expr { Expr::NumLit(s) => self.visit_num_lit(s), @@ -155,6 +167,8 @@ impl<'a> Generator<'a> { Expr::Filter(name, ref args) => self.visit_filter(name, args), Expr::BinOp(op, ref left, ref right) => self.visit_binop(op, left, right), + Expr::Call(ref obj, method, ref args) => + self.visit_call(obj, method, args), } } diff --git a/askama/src/parser.rs b/askama/src/parser.rs index c09eeb3..cad6468 100644 --- a/askama/src/parser.rs +++ b/askama/src/parser.rs @@ -9,6 +9,7 @@ pub enum Expr<'a> { Attr(Box<Expr<'a>>, &'a str), Filter(&'a str, Vec<Expr<'a>>), BinOp(&'a str, Box<Expr<'a>>, Box<Expr<'a>>), + Call(Box<Expr<'a>>, &'a str, Vec<Expr<'a>>), } #[derive(Debug)] @@ -137,7 +138,12 @@ named!(expr_attr<Expr>, alt!( obj: expr_single >> tag_s!(".") >> attr: identifier >> - (Expr::Attr(Box::new(obj), attr)) + args: arguments >> + (if args.is_some() { + Expr::Call(Box::new(obj), attr, args.unwrap()) + } else { + Expr::Attr(Box::new(obj), attr) + }) ) | expr_single )); |