From bef88f1696b828caf72695561c2270456f35894d Mon Sep 17 00:00:00 2001
From: yossyJ <28825627+yossyJ@users.noreply.github.com>
Date: Fri, 4 Jan 2019 23:12:44 +0900
Subject: Add support for tuple
---
askama_derive/src/parser.rs | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
(limited to 'askama_derive/src/parser.rs')
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, map!(identifier,
|s| Target::Name(s)
));
+named!(target_tuple, 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, map!(identifier,
|s| MatchVariant::Name(s)
));
@@ -703,7 +723,7 @@ named_args!(block_match<'a>(s: &'a Syntax<'a>) , Node<'a>>, do_parse!(
named!(block_let, 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, do_parse!(
named_args!(block_for<'a>(s: &'a Syntax<'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!("-")) >>
--
cgit