From 08dbe0a466cdfb3a35e19911ee364e6a0ed0f1d3 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 27 Apr 2018 13:44:19 +0200 Subject: Add support for unary operators (fixes #83) --- askama_derive/src/generator.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'askama_derive/src/generator.rs') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index b110a89..0050d35 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -620,6 +620,7 @@ impl<'a> Generator<'a> { Expr::Array(ref elements) => self.visit_array(elements, code), Expr::Attr(ref obj, name) => self.visit_attr(obj, name, code), Expr::Filter(name, ref args) => self.visit_filter(name, args, code), + Expr::Unary(op, ref inner) => self.visit_unary(op, inner, code), Expr::BinOp(op, ref left, ref right) => self.visit_binop(op, left, right, code), Expr::Group(ref inner) => self.visit_group(inner, code), Expr::MethodCall(ref obj, method, ref args) => { @@ -766,6 +767,12 @@ impl<'a> Generator<'a> { DisplayWrap::Unwrapped } + fn visit_unary(&mut self, op: &str, inner: &Expr, code: &mut String) -> DisplayWrap { + code.push_str(op); + self.visit_expr(inner, code); + DisplayWrap::Unwrapped + } + fn visit_binop(&mut self, op: &str, left: &Expr, right: &Expr, code: &mut String) -> DisplayWrap { self.visit_expr(left, code); -- cgit