aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/parser.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-10-20 10:09:50 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-10-20 10:09:50 +0200
commit4af73a868c7d35641f8a1bcd0a82f8c7db411d8d (patch)
tree1161aad02f2e453c1f800bc6a1730fbfb8bea671 /askama_shared/src/parser.rs
parent3d9048ab50b1030ff741371ed0d853fcc3ab5780 (diff)
downloadaskama-4af73a868c7d35641f8a1bcd0a82f8c7db411d8d.tar.gz
askama-4af73a868c7d35641f8a1bcd0a82f8c7db411d8d.tar.bz2
askama-4af73a868c7d35641f8a1bcd0a82f8c7db411d8d.zip
Add support for array literals (fixes #59)
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r--askama_shared/src/parser.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs
index 7cd8936..accefd2 100644
--- a/askama_shared/src/parser.rs
+++ b/askama_shared/src/parser.rs
@@ -7,6 +7,7 @@ pub enum Expr<'a> {
StrLit(&'a str),
Var(&'a str),
Path(Vec<&'a str>),
+ Array(Vec<Expr<'a>>),
Attr(Box<Expr<'a>>, &'a str),
Filter(&'a str, Vec<Expr<'a>>),
BinOp(&'a str, Box<Expr<'a>>, Box<Expr<'a>>),
@@ -128,6 +129,22 @@ named!(expr_num_lit<Expr>, map!(num_lit,
|s| Expr::NumLit(s)
));
+named!(expr_array_lit<Expr>, do_parse!(
+ ws!(tag_s!("[")) >>
+ first: expr_any >>
+ rest: many0!(do_parse!(
+ ws!(tag_s!(",")) >>
+ part: expr_any >>
+ (part)
+ )) >>
+ ws!(tag_s!("]")) >>
+ ({
+ let mut elements = vec![first];
+ elements.extend(rest);
+ Expr::Array(elements)
+ })
+));
+
named!(expr_str_lit<Expr>, map!(
delimited!(char!('"'), is_not!("\""), char!('"')),
|s| Expr::StrLit(str::from_utf8(s).unwrap())
@@ -204,6 +221,7 @@ named!(expr_single<Expr>, alt!(
expr_num_lit |
expr_str_lit |
expr_path |
+ expr_array_lit |
expr_var |
expr_group
));