Allow optional trailing comma in tuple parser
diff --git a/src/attr.rs b/src/attr.rs
index 9e69494..d818b4f 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -414,7 +414,7 @@
bang: punct!(!) >>
path_and_tts: brackets!(tuple!(
call!(Path::parse_mod_style),
- syn!(TokenStream)
+ syn!(TokenStream),
)) >>
({
let (bracket, (path, tts)) = path_and_tts;
@@ -454,7 +454,7 @@
pound: punct!(#) >>
path_and_tts: brackets!(tuple!(
call!(Path::parse_mod_style),
- syn!(TokenStream)
+ syn!(TokenStream),
)) >>
({
let (bracket, (path, tts)) = path_and_tts;
diff --git a/src/derive.rs b/src/derive.rs
index 3bf125c..ecef776 100644
--- a/src/derive.rs
+++ b/src/derive.rs
@@ -186,7 +186,7 @@
named!(data_union -> (Option<WhereClause>, FieldsNamed), tuple!(
option!(syn!(WhereClause)),
- syn!(FieldsNamed)
+ syn!(FieldsNamed),
));
}
diff --git a/src/expr.rs b/src/expr.rs
index 4206e37..a6f94fc 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1712,7 +1712,7 @@
outer_attrs: many0!(Attribute::parse_outer) >>
e: parens!(tuple!(
many0!(Attribute::parse_inner),
- syn!(Expr)
+ syn!(Expr),
)) >>
(ExprParen {
attrs: {
@@ -1736,7 +1736,7 @@
outer_attrs: many0!(Attribute::parse_outer) >>
elems: brackets!(tuple!(
many0!(Attribute::parse_inner),
- call!(Punctuated::parse_terminated)
+ call!(Punctuated::parse_terminated),
)) >>
(ExprArray {
attrs: {
@@ -1765,7 +1765,7 @@
punct!(::),
punct!(<),
call!(Punctuated::parse_terminated),
- punct!(>)
+ punct!(>),
)) >>
args: parens!(Punctuated::parse_terminated) >>
({
@@ -1806,7 +1806,7 @@
outer_attrs: many0!(Attribute::parse_outer) >>
elems: parens!(tuple!(
many0!(Attribute::parse_inner),
- call!(Punctuated::parse_terminated)
+ call!(Punctuated::parse_terminated),
)) >>
(ExprTuple {
attrs: {
@@ -1911,7 +1911,7 @@
expr: expr_no_struct >>
block: braces!(tuple!(
many0!(Attribute::parse_inner),
- call!(Block::parse_within)
+ call!(Block::parse_within),
)) >>
(ExprForLoop {
attrs: {
@@ -1944,7 +1944,7 @@
loop_: keyword!(loop) >>
block: braces!(tuple!(
many0!(Attribute::parse_inner),
- call!(Block::parse_within)
+ call!(Block::parse_within),
)) >>
(ExprLoop {
attrs: {
@@ -1974,7 +1974,7 @@
obj: expr_no_struct >>
braced_content: braces!(tuple!(
many0!(Attribute::parse_inner),
- many0!(syn!(Arm))
+ many0!(syn!(Arm)),
)) >>
(ExprMatch {
attrs: {
@@ -2127,7 +2127,7 @@
cond: expr_no_struct >>
block: braces!(tuple!(
many0!(Attribute::parse_inner),
- call!(Block::parse_within)
+ call!(Block::parse_within),
)) >>
(ExprWhile {
attrs: {
@@ -2162,7 +2162,7 @@
value: expr_no_struct >>
block: braces!(tuple!(
many0!(Attribute::parse_inner),
- call!(Block::parse_within)
+ call!(Block::parse_within),
)) >>
(ExprWhileLet {
attrs: {
@@ -2334,7 +2334,7 @@
many0!(Attribute::parse_inner),
syn!(Expr),
punct!(;),
- syn!(Expr)
+ syn!(Expr),
)) >>
(ExprRepeat {
attrs: {
@@ -2377,7 +2377,7 @@
outer_attrs: many0!(Attribute::parse_outer) >>
block: braces!(tuple!(
many0!(Attribute::parse_inner),
- call!(Block::parse_within)
+ call!(Block::parse_within),
)) >>
(ExprBlock {
attrs: {
diff --git a/src/item.rs b/src/item.rs
index ebe2cb9..080f7fc 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -954,7 +954,7 @@
where_clause: option!(syn!(WhereClause)) >>
inner_attrs_stmts: braces!(tuple!(
many0!(Attribute::parse_inner),
- call!(Block::parse_within)
+ call!(Block::parse_within),
)) >>
(ItemFn {
attrs: {
@@ -1045,7 +1045,7 @@
braces!(
tuple!(
many0!(Attribute::parse_inner),
- many0!(Item::parse)
+ many0!(Item::parse),
)
) => {|(brace, (inner_attrs, items))| (
inner_attrs,
@@ -1072,7 +1072,7 @@
abi: syn!(Abi) >>
braced_content: braces!(tuple!(
many0!(Attribute::parse_inner),
- many0!(ForeignItem::parse)
+ many0!(ForeignItem::parse),
)) >>
(ItemForeignMod {
attrs: {
@@ -1396,7 +1396,7 @@
where_clause: option!(syn!(WhereClause)) >>
inner: braces!(tuple!(
many0!(Attribute::parse_inner),
- many0!(ImplItem::parse)
+ many0!(ImplItem::parse),
)) >>
(ItemImpl {
attrs: {
@@ -1468,7 +1468,7 @@
where_clause: option!(syn!(WhereClause)) >>
inner_attrs_stmts: braces!(tuple!(
many0!(Attribute::parse_inner),
- call!(Block::parse_within)
+ call!(Block::parse_within),
)) >>
(ImplItemMethod {
attrs: {
diff --git a/src/parsers.rs b/src/parsers.rs
index 8be5dde..400c0ca 100644
--- a/src/parsers.rs
+++ b/src/parsers.rs
@@ -749,8 +749,8 @@
/// *This macro is available if Syn is built with the `"parsing"` feature.*
#[macro_export]
macro_rules! tuple {
- ($i:expr, $($rest:tt)*) => {
- tuple_parser!($i, (), $($rest)*)
+ ($i:expr, $($rest:tt)+) => {
+ tuple_parser!($i, (), $($rest)+)
};
}
@@ -758,47 +758,34 @@
#[doc(hidden)]
#[macro_export]
macro_rules! tuple_parser {
- ($i:expr, ($($parsed:tt),*), $e:ident, $($rest:tt)*) => {
- tuple_parser!($i, ($($parsed),*), call!($e), $($rest)*)
+ ($i:expr, ($($parsed:ident,)*), $e:ident) => {
+ tuple_parser!($i, ($($parsed,)*), call!($e))
};
- ($i:expr, (), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => {
+ ($i:expr, ($($parsed:ident,)*), $e:ident, $($rest:tt)*) => {
+ tuple_parser!($i, ($($parsed,)*), call!($e), $($rest)*)
+ };
+
+ ($i:expr, ($($parsed:ident,)*), $submac:ident!( $($args:tt)* )) => {
match $submac!($i, $($args)*) {
::std::result::Result::Err(err) =>
::std::result::Result::Err(err),
::std::result::Result::Ok((o, i)) =>
- tuple_parser!(i, (o), $($rest)*),
+ ::std::result::Result::Ok((($($parsed,)* o,), i)),
}
};
- ($i:expr, ($($parsed:tt)*), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => {
+ ($i:expr, ($($parsed:ident,)*), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => {
match $submac!($i, $($args)*) {
::std::result::Result::Err(err) =>
::std::result::Result::Err(err),
::std::result::Result::Ok((o, i)) =>
- tuple_parser!(i, ($($parsed)* , o), $($rest)*),
+ tuple_parser!(i, ($($parsed,)* o,), $($rest)*),
}
};
- ($i:expr, ($($parsed:tt),*), $e:ident) => {
- tuple_parser!($i, ($($parsed),*), call!($e))
- };
-
- ($i:expr, (), $submac:ident!( $($args:tt)* )) => {
- $submac!($i, $($args)*)
- };
-
- ($i:expr, ($($parsed:expr),*), $submac:ident!( $($args:tt)* )) => {
- match $submac!($i, $($args)*) {
- ::std::result::Result::Err(err) =>
- ::std::result::Result::Err(err),
- ::std::result::Result::Ok((o, i)) =>
- ::std::result::Result::Ok((($($parsed),*, o), i)),
- }
- };
-
- ($i:expr, ($($parsed:expr),*)) => {
- ::std::result::Result::Ok((($($parsed),*), $i))
+ ($i:expr, ($($parsed:ident,)*),) => {
+ ::std::result::Result::Ok((($($parsed,)*), $i))
};
}