diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-22 20:22:33 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-22 20:22:33 +0200 |
commit | 544f9b11926b6ccad1bc4e7a6842c5421f9f1576 (patch) | |
tree | 2648ef7916eaec94f368ed9c70917343687518c8 /askama_derive/src | |
parent | 3652708020cf86c0cd075d0f827c51500a5aabaa (diff) | |
download | askama-544f9b11926b6ccad1bc4e7a6842c5421f9f1576.tar.gz askama-544f9b11926b6ccad1bc4e7a6842c5421f9f1576.tar.bz2 askama-544f9b11926b6ccad1bc4e7a6842c5421f9f1576.zip |
Refactor parser handling of arguments
Diffstat (limited to 'askama_derive/src')
-rw-r--r-- | askama_derive/src/parser.rs | 40 |
1 files 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<Target>, map!(identifier, |s| Target::Name(s) )); -named!(arguments<Option<Vec<Expr>>>, 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<Vec<Expr>>, 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<Vec<&'a str>>, do_parse!( @@ -182,7 +180,7 @@ named!(expr_single<Expr>, alt!( named!(attr<(&str, Option<Vec<Expr>>)>, do_parse!( tag_s!(".") >> attr: identifier >> - args: arguments >> + args: opt!(arguments) >> (attr, args) )); @@ -205,7 +203,7 @@ named!(expr_attr<Expr>, do_parse!( named!(filter<(&str, Option<Vec<Expr>>)>, do_parse!( tag_s!("|") >> fname: identifier >> - args: arguments >> + args: opt!(arguments) >> (fname, args) )); |