diff options
Diffstat (limited to '')
-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!("-")) >> |