diff options
author | yossyJ <28825627+yossyJ@users.noreply.github.com> | 2019-01-04 23:12:44 +0900 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2019-01-04 16:58:09 +0100 |
commit | bef88f1696b828caf72695561c2270456f35894d (patch) | |
tree | fb83e8f9fe1b05a49c18c43adef96a366dc18f6e /askama_derive/src/parser.rs | |
parent | 39e08325c0e0fba75384579427d1c6f7eca8fbc9 (diff) | |
download | askama-bef88f1696b828caf72695561c2270456f35894d.tar.gz askama-bef88f1696b828caf72695561c2270456f35894d.tar.bz2 askama-bef88f1696b828caf72695561c2270456f35894d.zip |
Add support for tuple
Diffstat (limited to 'askama_derive/src/parser.rs')
-rw-r--r-- | askama_derive/src/parser.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index 81935f6..c5e610e 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -42,6 +42,7 @@ pub enum MatchParameter<'a> { #[derive(Debug)] pub enum Target<'a> { Name(&'a str), + Tuple(Vec<&'a str>), } #[derive(Clone, Copy, Debug)] @@ -275,6 +276,25 @@ named!(target_single<Input, Target>, map!(identifier, |s| Target::Name(s) )); +named!(target_tuple<Input, Target>, do_parse!( + tag!("(") >> + args: opt!(do_parse!( + arg0: ws!(identifier) >> + args: many0!(do_parse!( + tag!(",") >> + argn: ws!(identifier) >> + (argn) + )) >> + ({ + let mut res = vec![arg0]; + res.extend(args); + res + }) + )) >> + tag!(")") >> + (Target::Tuple(args.unwrap_or_default())) +)); + named!(variant_name<Input, MatchVariant>, map!(identifier, |s| MatchVariant::Name(s) )); @@ -703,7 +723,7 @@ named_args!(block_match<'a>(s: &'a Syntax<'a>) <Input<'a>, Node<'a>>, do_parse!( named!(block_let<Input, Node>, do_parse!( pws: opt!(tag!("-")) >> ws!(tag!("let")) >> - var: ws!(target_single) >> + var: ws!(alt!(target_single | target_tuple)) >> val: opt!(do_parse!( ws!(tag!("=")) >> val: ws!(expr_any) >> @@ -720,7 +740,7 @@ named!(block_let<Input, Node>, do_parse!( named_args!(block_for<'a>(s: &'a Syntax<'a>) <Input<'a>, Node<'a>>, do_parse!( pws1: opt!(tag!("-")) >> ws!(tag!("for")) >> - var: ws!(target_single) >> + var: ws!(alt!(target_single | target_tuple)) >> ws!(tag!("in")) >> iter: ws!(expr_any) >> nws1: opt!(tag!("-")) >> |