aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-23 18:17:33 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-23 18:18:37 +0200
commita46966b4ad0f9223d7e5e12d675b337a048afd3e (patch)
tree26d72c688ca58290966395a1b4822539f326720c /askama_derive/src/generator.rs
parent6eb8e4f65c159204413b294a6b47007847ad1577 (diff)
downloadaskama-a46966b4ad0f9223d7e5e12d675b337a048afd3e.tar.gz
askama-a46966b4ad0f9223d7e5e12d675b337a048afd3e.tar.bz2
askama-a46966b4ad0f9223d7e5e12d675b337a048afd3e.zip
Add support for range operators (see #95)
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r--askama_derive/src/generator.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 0e86a27..5ec2238 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -598,6 +598,7 @@ impl<'a> Generator<'a> {
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::Range(op, ref left, ref right) => self.visit_range(op, left, right, code),
Expr::Group(ref inner) => self.visit_group(inner, code),
Expr::MethodCall(ref obj, method, ref args) => {
self.visit_method_call(obj, method, args, code)
@@ -762,6 +763,23 @@ impl<'a> Generator<'a> {
DisplayWrap::Unwrapped
}
+ fn visit_range(
+ &mut self,
+ op: &str,
+ left: &Option<Box<Expr>>,
+ right: &Option<Box<Expr>>,
+ code: &mut String,
+ ) -> DisplayWrap {
+ if let Some(left) = left {
+ self.visit_expr(left, code);
+ }
+ code.push_str(op);
+ if let Some(right) = right {
+ self.visit_expr(right, code);
+ }
+ DisplayWrap::Unwrapped
+ }
+
fn visit_binop(
&mut self,
op: &str,