From d497a31e059292f7b37b46c6f17b489e9f3623b0 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 4 Oct 2017 21:08:43 +0200 Subject: Handle path expressions (fixes #56) --- askama_shared/src/parser.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'askama_shared/src/parser.rs') diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 083e96b..495b68f 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -6,6 +6,7 @@ pub enum Expr<'a> { NumLit(&'a str), StrLit(&'a str), Var(&'a str), + Path(Vec<&'a str>), Attr(Box>, &'a str), Filter(&'a str, Vec>), BinOp(&'a str, Box>, Box>), @@ -136,6 +137,22 @@ named!(expr_var, map!(identifier, |s| Expr::Var(s)) ); +named!(expr_path, do_parse!( + start: call!(identifier) >> + rest: many1!(do_parse!( + tag_s!("::") >> + part: identifier >> + (part) + )) >> + ({ + let mut path = vec![ start ]; + for part in rest.iter() { + path.push(part); + } + Expr::Path(path) + }) +)); + named!(target_single, map!(identifier, |s| Target::Name(s) )); @@ -186,6 +203,7 @@ named!(expr_group, map!( named!(expr_single, alt!( expr_num_lit | expr_str_lit | + expr_path | expr_var | expr_group )); -- cgit