From 544f9b11926b6ccad1bc4e7a6842c5421f9f1576 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 22 Aug 2017 20:22:33 +0200 Subject: Refactor parser handling of arguments --- askama_derive/src/parser.rs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index 9a49715..dad7e84 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -127,25 +127,23 @@ named!(target_single, map!(identifier, |s| Target::Name(s) )); -named!(arguments>>, opt!( - do_parse!( - tag_s!("(") >> - arg0: ws!(opt!(expr_any)) >> - args: many0!(do_parse!( - tag_s!(",") >> - argn: ws!(expr_any) >> - (argn) - )) >> - tag_s!(")") >> - ({ - let mut res = Vec::new(); - if arg0.is_some() { - res.push(arg0.unwrap()); - } - res.extend(args); - res - }) - ) +named!(arguments>, do_parse!( + tag_s!("(") >> + arg0: ws!(opt!(expr_any)) >> + args: many0!(do_parse!( + tag_s!(",") >> + argn: ws!(expr_any) >> + (argn) + )) >> + tag_s!(")") >> + ({ + let mut res = Vec::new(); + if arg0.is_some() { + res.push(arg0.unwrap()); + } + res.extend(args); + res + }) )); named!(parameters>, do_parse!( @@ -182,7 +180,7 @@ named!(expr_single, alt!( named!(attr<(&str, Option>)>, do_parse!( tag_s!(".") >> attr: identifier >> - args: arguments >> + args: opt!(arguments) >> (attr, args) )); @@ -205,7 +203,7 @@ named!(expr_attr, do_parse!( named!(filter<(&str, Option>)>, do_parse!( tag_s!("|") >> fname: identifier >> - args: arguments >> + args: opt!(arguments) >> (fname, args) )); -- cgit