From 71d99927a63bc406023484ab21f885cd985c9a88 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 26 May 2017 11:45:01 +0200 Subject: Add support for chained attributes (fixes #22) --- askama_derive/src/parser.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'askama_derive/src') 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, alt!( expr_group )); -named!(expr_attr, 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>)>, do_parse!( + tag_s!(".") >> + attr: identifier >> + args: arguments >> + (attr, args) +)); + +named!(expr_attr, 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>)>, do_parse!( -- cgit