diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-05-26 11:45:01 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-05-26 11:45:27 +0200 |
commit | 71d99927a63bc406023484ab21f885cd985c9a88 (patch) | |
tree | 1cda482246f500d8afe67f1ba38b0ef0874e5522 /askama_derive | |
parent | 52733424e789757037539a6f4a8cf5129eeb6655 (diff) | |
download | askama-71d99927a63bc406023484ab21f885cd985c9a88.tar.gz askama-71d99927a63bc406023484ab21f885cd985c9a88.tar.bz2 askama-71d99927a63bc406023484ab21f885cd985c9a88.zip |
Add support for chained attributes (fixes #22)
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/src/parser.rs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index ce13add..9a9c89e 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -141,18 +141,27 @@ named!(expr_single<Expr>, alt!( expr_group )); -named!(expr_attr<Expr>, alt!( - do_parse!( - obj: expr_single >> - tag_s!(".") >> - attr: identifier >> - args: arguments >> - (if args.is_some() { - Expr::Call(Box::new(obj), attr, args.unwrap()) - } else { - Expr::Attr(Box::new(obj), attr) - }) - ) | expr_single +named!(attr<(&str, Option<Vec<Expr>>)>, do_parse!( + tag_s!(".") >> + attr: identifier >> + args: arguments >> + (attr, args) +)); + +named!(expr_attr<Expr>, do_parse!( + obj: expr_single >> + attrs: many0!(attr) >> + ({ + let mut res = obj; + for (aname, args) in attrs { + res = if args.is_some() { + Expr::Call(Box::new(res), aname, args.unwrap()) + } else { + Expr::Attr(Box::new(res), aname) + }; + } + res + }) )); named!(filter<(&str, Option<Vec<Expr>>)>, do_parse!( |