diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-17 17:15:45 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-17 17:15:45 +0100 |
commit | 7a6e79187ee1a86d0c71f160ac00fa9f5a290134 (patch) | |
tree | 92d7750220b50b67b8ca8c4fc2deaeee014a53a0 | |
parent | 825610cd64237c877f26cc882cac20704c80e046 (diff) | |
download | askama-7a6e79187ee1a86d0c71f160ac00fa9f5a290134.tar.gz askama-7a6e79187ee1a86d0c71f160ac00fa9f5a290134.tar.bz2 askama-7a6e79187ee1a86d0c71f160ac00fa9f5a290134.zip |
Add support for integer literals
Diffstat (limited to '')
-rw-r--r-- | askama/src/generator.rs | 5 | ||||
-rw-r--r-- | askama/src/parser.rs | 6 | ||||
-rw-r--r-- | testing/templates/operators.html | 2 |
3 files changed, 12 insertions, 1 deletions
diff --git a/askama/src/generator.rs b/askama/src/generator.rs index e768219..a8d62af 100644 --- a/askama/src/generator.rs +++ b/askama/src/generator.rs @@ -103,6 +103,10 @@ impl<'a> Generator<'a> { self.prepare_ws(ws); } + fn visit_num_lit(&mut self, s: &str) { + self.write(s); + } + fn visit_str_lit(&mut self, s: &str) { self.write(&format!("\"{}\"", s)); } @@ -129,6 +133,7 @@ impl<'a> Generator<'a> { fn visit_expr(&mut self, expr: &Expr) { match *expr { + Expr::NumLit(s) => self.visit_num_lit(s), 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), diff --git a/askama/src/parser.rs b/askama/src/parser.rs index 6d0e58f..1d34611 100644 --- a/askama/src/parser.rs +++ b/askama/src/parser.rs @@ -3,6 +3,7 @@ use std::str; #[derive(Debug)] pub enum Expr<'a> { + NumLit(&'a str), StrLit(&'a str), Var(&'a str), Filter(&'a str, Box<Expr<'a>>), @@ -72,6 +73,10 @@ fn take_content(i: &[u8]) -> IResult<&[u8], Node> { IResult::Done(&i[..0], split_ws_parts(&i[..])) } +named!(expr_num_lit<Expr>, map!(nom::digit, + |s| Expr::NumLit(str::from_utf8(s).unwrap()) +)); + named!(expr_str_lit<Expr>, map!( delimited!(char!('"'), is_not!("\""), char!('"')), |s| Expr::StrLit(str::from_utf8(s).unwrap()) @@ -86,6 +91,7 @@ named!(target_single<Target>, map!(alphanumeric, )); named!(expr_single<Expr>, alt!( + expr_num_lit | expr_str_lit | expr_var )); diff --git a/testing/templates/operators.html b/testing/templates/operators.html index 1488b9a..4b093c5 100644 --- a/testing/templates/operators.html +++ b/testing/templates/operators.html @@ -28,6 +28,6 @@ {% if a == b && a + b == c -%} and {%- endif -%} -{% if a == c || a == b -%} +{% if a == c || a == 1 -%} or {%- endif -%} |