accept async functions and async closures as verbatim
diff --git a/src/expr.rs b/src/expr.rs
index 2a03c2d..5df8187 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1609,6 +1609,8 @@
|
call!(expr_closure, allow_struct)
|
+ call!(expr_unstable_async_closure, allow_struct)
+ |
cond_reduce!(allow_block, syn!(ExprBlock)) => { Expr::Block }
|
// NOTE: This is the prefix-form of range
@@ -2123,6 +2125,45 @@
));
#[cfg(feature = "full")]
+ fn grab_cursor(cursor: Cursor) -> PResult<Cursor> {
+ Ok((cursor, cursor))
+ }
+
+ #[cfg(feature = "full")]
+ named!(expr_unstable_async_closure(allow_struct: bool) -> Expr, do_parse!(
+ begin: call!(grab_cursor) >>
+ _attrs: many0!(Attribute::parse_outer) >>
+ _asyncness: option!(keyword!(async)) >>
+ _movability: option!(keyword!(static)) >>
+ _capture: option!(keyword!(move)) >>
+ _or1: punct!(|) >>
+ _inputs: call!(Punctuated::<FnArg, Token![,]>::parse_terminated_with, fn_arg) >>
+ _or2: punct!(|) >>
+ _ret_and_body: alt!(
+ do_parse!(
+ arrow: punct!(->) >>
+ ty: syn!(Type) >>
+ body: syn!(Block) >>
+ (ReturnType::Type(arrow, Box::new(ty)),
+ Expr::Block(ExprBlock {
+ attrs: Vec::new(),
+ block: body,
+ }))
+ )
+ |
+ map!(ambiguous_expr!(allow_struct), |e| (ReturnType::Default, e))
+ ) >>
+ end: call!(grab_cursor) >>
+ ({
+ let tts = begin.token_stream().into_iter().collect::<Vec<_>>();
+ let len = tts.len() - end.token_stream().into_iter().count();
+ ExprVerbatim {
+ tts: tts.into_iter().take(len).collect(),
+ }.into()
+ })
+ ));
+
+ #[cfg(feature = "full")]
named!(fn_arg -> FnArg, do_parse!(
pat: syn!(Pat) >>
ty: option!(tuple!(punct!(:), syn!(Type))) >>
diff --git a/src/item.rs b/src/item.rs
index 080f7fc..53ea4a0 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -714,7 +714,8 @@
pub mod parsing {
use super::*;
- use synom::Synom;
+ use buffer::Cursor;
+ use synom::{PResult, Synom};
impl_synom!(Item "item" alt!(
syn!(ItemExternCrate) => { Item::ExternCrate }
@@ -727,6 +728,8 @@
|
syn!(ItemFn) => { Item::Fn }
|
+ call!(unstable_async_fn) => { Item::Verbatim }
+ |
syn!(ItemMod) => { Item::Mod }
|
syn!(ItemForeignMod) => { Item::ForeignMod }
@@ -985,6 +988,38 @@
})
));
+ fn grab_cursor(cursor: Cursor) -> PResult<Cursor> {
+ Ok((cursor, cursor))
+ }
+
+ named!(unstable_async_fn -> ItemVerbatim, do_parse!(
+ begin: call!(grab_cursor) >>
+ _outer_attrs: many0!(Attribute::parse_outer) >>
+ _vis: syn!(Visibility) >>
+ _constness: option!(keyword!(const)) >>
+ _unsafety: option!(keyword!(unsafe)) >>
+ _asyncness: option!(keyword!(async)) >>
+ _abi: option!(syn!(Abi)) >>
+ _fn_: keyword!(fn) >>
+ _ident: syn!(Ident) >>
+ _generics: syn!(Generics) >>
+ _inputs: parens!(Punctuated::<FnArg, Token![,]>::parse_terminated) >>
+ _ret: syn!(ReturnType) >>
+ _where_clause: option!(syn!(WhereClause)) >>
+ _inner_attrs_stmts: braces!(tuple!(
+ many0!(Attribute::parse_inner),
+ call!(Block::parse_within),
+ )) >>
+ end: call!(grab_cursor) >>
+ ({
+ let tts = begin.token_stream().into_iter().collect::<Vec<_>>();
+ let len = tts.len() - end.token_stream().into_iter().count();
+ ItemVerbatim {
+ tts: tts.into_iter().take(len).collect(),
+ }
+ })
+ ));
+
impl Synom for FnArg {
named!(parse -> Self, alt!(
do_parse!(