Parse try-blocks as Expr::TryBlock
diff --git a/src/expr.rs b/src/expr.rs
index 748f4a5..2b7aebb 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -509,13 +509,12 @@
pub question_token: Token![?],
}),
- /// A catch expression: `do catch { ... }`.
+ /// A try block: `try { ... }`.
///
/// *This type is available if Syn is built with the `"full"` feature.*
- pub Catch(ExprCatch #full {
+ pub TryBlock(ExprTryBlock #full {
pub attrs: Vec<Attribute>,
- pub do_token: Token![do],
- pub catch_token: Token![catch],
+ pub try_token: Token![try],
pub block: Block,
}),
@@ -601,7 +600,7 @@
| Expr::Paren(ExprParen { ref mut attrs, .. })
| Expr::Group(ExprGroup { ref mut attrs, .. })
| Expr::Try(ExprTry { ref mut attrs, .. })
- | Expr::Catch(ExprCatch { ref mut attrs, .. })
+ | Expr::TryBlock(ExprTryBlock { ref mut attrs, .. })
| Expr::Yield(ExprYield { ref mut attrs, .. }) => mem::replace(attrs, new),
Expr::Verbatim(_) => {
// TODO
@@ -1009,7 +1008,7 @@
| Expr::WhileLet(..)
| Expr::Loop(..)
| Expr::ForLoop(..)
- | Expr::Catch(..) => false,
+ | Expr::TryBlock(..) => false,
_ => true,
}
}
@@ -1575,7 +1574,7 @@
call!(unstable_async_block) => { Expr::Verbatim }
|
// must be before ExprStruct
- call!(unstable_try_block) => { Expr::Verbatim }
+ syn!(ExprTryBlock) => { Expr::TryBlock }
|
// must be before expr_path
cond_reduce!(allow_struct, syn!(ExprStruct)) => { Expr::Struct }
@@ -1608,8 +1607,6 @@
|
syn!(ExprMatch) => { Expr::Match }
|
- syn!(ExprCatch) => { Expr::Catch }
- |
syn!(ExprYield) => { Expr::Yield }
|
syn!(ExprUnsafe) => { Expr::Unsafe }
@@ -1654,7 +1651,7 @@
|
syn!(ExprMatch) => { Expr::Match }
|
- syn!(ExprCatch) => { Expr::Catch }
+ syn!(ExprTryBlock) => { Expr::TryBlock }
|
syn!(ExprYield) => { Expr::Yield }
|
@@ -2028,21 +2025,19 @@
}
#[cfg(feature = "full")]
- impl Synom for ExprCatch {
+ impl Synom for ExprTryBlock {
named!(parse -> Self, do_parse!(
- do_: keyword!(do) >>
- catch_: keyword!(catch) >>
- catch_block: syn!(Block) >>
- (ExprCatch {
+ try_token: keyword!(try) >>
+ block: syn!(Block) >>
+ (ExprTryBlock {
attrs: Vec::new(),
- block: catch_block,
- do_token: do_,
- catch_token: catch_,
+ try_token: try_token,
+ block: block,
})
));
fn description() -> Option<&'static str> {
- Some("`catch` expression")
+ Some("`try` block")
}
}
@@ -2152,18 +2147,6 @@
));
#[cfg(feature = "full")]
- named!(unstable_try_block -> ExprVerbatim, do_parse!(
- begin: call!(verbatim::grab_cursor) >>
- many0!(Attribute::parse_outer) >>
- keyword!(try) >>
- syn!(Block) >>
- end: call!(verbatim::grab_cursor) >>
- (ExprVerbatim {
- tts: verbatim::token_range(begin..end),
- })
- ));
-
- #[cfg(feature = "full")]
named!(fn_arg -> FnArg, do_parse!(
pat: syn!(Pat) >>
ty: option!(tuple!(punct!(:), syn!(Type))) >>
@@ -3412,11 +3395,10 @@
}
#[cfg(feature = "full")]
- impl ToTokens for ExprCatch {
+ impl ToTokens for ExprTryBlock {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
- self.do_token.to_tokens(tokens);
- self.catch_token.to_tokens(tokens);
+ self.try_token.to_tokens(tokens);
self.block.to_tokens(tokens);
}
}
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index 450aec9..85d0ca8 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -161,11 +161,6 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
- fn fold_expr_catch(&mut self, i: ExprCatch) -> ExprCatch {
- fold_expr_catch(self, i)
- }
- #[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_closure(&mut self, i: ExprClosure) -> ExprClosure {
fold_expr_closure(self, i)
}
@@ -271,6 +266,11 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
+ fn fold_expr_try_block(&mut self, i: ExprTryBlock) -> ExprTryBlock {
+ fold_expr_try_block(self, i)
+ }
+ #[cfg(feature = "full")]
+ #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_tuple(&mut self, i: ExprTuple) -> ExprTuple {
fold_expr_tuple(self, i)
}
@@ -1206,7 +1206,9 @@
Expr::Paren(_binding_0) => Expr::Paren(_visitor.fold_expr_paren(_binding_0)),
Expr::Group(_binding_0) => Expr::Group(full!(_visitor.fold_expr_group(_binding_0))),
Expr::Try(_binding_0) => Expr::Try(full!(_visitor.fold_expr_try(_binding_0))),
- Expr::Catch(_binding_0) => Expr::Catch(full!(_visitor.fold_expr_catch(_binding_0))),
+ Expr::TryBlock(_binding_0) => {
+ Expr::TryBlock(full!(_visitor.fold_expr_try_block(_binding_0)))
+ }
Expr::Yield(_binding_0) => Expr::Yield(full!(_visitor.fold_expr_yield(_binding_0))),
Expr::Verbatim(_binding_0) => Expr::Verbatim(_visitor.fold_expr_verbatim(_binding_0)),
}
@@ -1296,16 +1298,6 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
-pub fn fold_expr_catch<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprCatch) -> ExprCatch {
- ExprCatch {
- attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
- do_token: Token ! [ do ](tokens_helper(_visitor, &_i.do_token.span)),
- catch_token: Token),
- block: _visitor.fold_block(_i.block),
- }
-}
-#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_closure<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprClosure) -> ExprClosure {
ExprClosure {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1544,6 +1536,15 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
+pub fn fold_expr_try_block<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprTryBlock) -> ExprTryBlock {
+ ExprTryBlock {
+ attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
+ try_token: Token),
+ block: _visitor.fold_block(_i.block),
+ }
+}
+#[cfg(feature = "full")]
+#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_tuple<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprTuple) -> ExprTuple {
ExprTuple {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index f0bf8bf..596bd3e 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -161,11 +161,6 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
- fn visit_expr_catch(&mut self, i: &'ast ExprCatch) {
- visit_expr_catch(self, i)
- }
- #[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_closure(&mut self, i: &'ast ExprClosure) {
visit_expr_closure(self, i)
}
@@ -271,6 +266,11 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
+ fn visit_expr_try_block(&mut self, i: &'ast ExprTryBlock) {
+ visit_expr_try_block(self, i)
+ }
+ #[cfg(feature = "full")]
+ #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_tuple(&mut self, i: &'ast ExprTuple) {
visit_expr_tuple(self, i)
}
@@ -1256,8 +1256,8 @@
Expr::Try(ref _binding_0) => {
full!(_visitor.visit_expr_try(_binding_0));
}
- Expr::Catch(ref _binding_0) => {
- full!(_visitor.visit_expr_catch(_binding_0));
+ Expr::TryBlock(ref _binding_0) => {
+ full!(_visitor.visit_expr_try_block(_binding_0));
}
Expr::Yield(ref _binding_0) => {
full!(_visitor.visit_expr_yield(_binding_0));
@@ -1365,16 +1365,6 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
-pub fn visit_expr_catch<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprCatch) {
- for it in &_i.attrs {
- _visitor.visit_attribute(it)
- }
- tokens_helper(_visitor, &_i.do_token.span);
- tokens_helper(_visitor, &_i.catch_token.span);
- _visitor.visit_block(&_i.block);
-}
-#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_closure<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprClosure) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1657,6 +1647,18 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
+pub fn visit_expr_try_block<'ast, V: Visit<'ast> + ?Sized>(
+ _visitor: &mut V,
+ _i: &'ast ExprTryBlock,
+) {
+ for it in &_i.attrs {
+ _visitor.visit_attribute(it)
+ }
+ tokens_helper(_visitor, &_i.try_token.span);
+ _visitor.visit_block(&_i.block);
+}
+#[cfg(feature = "full")]
+#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_tuple<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprTuple) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 16e1583..cf6ca4f 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -165,11 +165,6 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
- fn visit_expr_catch_mut(&mut self, i: &mut ExprCatch) {
- visit_expr_catch_mut(self, i)
- }
- #[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_closure_mut(&mut self, i: &mut ExprClosure) {
visit_expr_closure_mut(self, i)
}
@@ -275,6 +270,11 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
+ fn visit_expr_try_block_mut(&mut self, i: &mut ExprTryBlock) {
+ visit_expr_try_block_mut(self, i)
+ }
+ #[cfg(feature = "full")]
+ #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_tuple_mut(&mut self, i: &mut ExprTuple) {
visit_expr_tuple_mut(self, i)
}
@@ -1254,8 +1254,8 @@
Expr::Try(ref mut _binding_0) => {
full!(_visitor.visit_expr_try_mut(_binding_0));
}
- Expr::Catch(ref mut _binding_0) => {
- full!(_visitor.visit_expr_catch_mut(_binding_0));
+ Expr::TryBlock(ref mut _binding_0) => {
+ full!(_visitor.visit_expr_try_block_mut(_binding_0));
}
Expr::Yield(ref mut _binding_0) => {
full!(_visitor.visit_expr_yield_mut(_binding_0));
@@ -1360,16 +1360,6 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
-pub fn visit_expr_catch_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprCatch) {
- for it in &mut _i.attrs {
- _visitor.visit_attribute_mut(it)
- }
- tokens_helper(_visitor, &mut _i.do_token.span);
- tokens_helper(_visitor, &mut _i.catch_token.span);
- _visitor.visit_block_mut(&mut _i.block);
-}
-#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_closure_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprClosure) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1643,6 +1633,15 @@
}
#[cfg(feature = "full")]
#[cfg(any(feature = "full", feature = "derive"))]
+pub fn visit_expr_try_block_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprTryBlock) {
+ for it in &mut _i.attrs {
+ _visitor.visit_attribute_mut(it)
+ }
+ tokens_helper(_visitor, &mut _i.try_token.span);
+ _visitor.visit_block_mut(&mut _i.block);
+}
+#[cfg(feature = "full")]
+#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_tuple_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprTuple) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
diff --git a/src/lib.rs b/src/lib.rs
index e09ea39..9f92989 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -335,9 +335,9 @@
#[cfg(any(feature = "full", feature = "derive"))]
pub use expr::{
Expr, ExprArray, ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox, ExprBreak, ExprCall,
- ExprCast, ExprCatch, ExprClosure, ExprContinue, ExprField, ExprForLoop, ExprGroup, ExprIf,
- ExprIfLet, ExprInPlace, ExprIndex, ExprLit, ExprLoop, ExprMacro, ExprMatch, ExprMethodCall,
- ExprParen, ExprPath, ExprRange, ExprReference, ExprRepeat, ExprReturn, ExprStruct, ExprTry,
+ ExprCast, ExprClosure, ExprContinue, ExprField, ExprForLoop, ExprGroup, ExprIf, ExprIfLet,
+ ExprInPlace, ExprIndex, ExprLit, ExprLoop, ExprMacro, ExprMatch, ExprMethodCall, ExprParen,
+ ExprPath, ExprRange, ExprReference, ExprRepeat, ExprReturn, ExprStruct, ExprTry, ExprTryBlock,
ExprTuple, ExprType, ExprUnary, ExprUnsafe, ExprVerbatim, ExprWhile, ExprWhileLet, ExprYield,
Index, Member,
};
diff --git a/src/token.rs b/src/token.rs
index d5b7f06..dd8a84b 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -494,12 +494,10 @@
"box" pub struct Box /// `box`
"break" pub struct Break /// `break`
"Self" pub struct CapSelf /// `Self`
- "catch" pub struct Catch /// `catch`
"const" pub struct Const /// `const`
"continue" pub struct Continue /// `continue`
"crate" pub struct Crate /// `crate`
"default" pub struct Default /// `default`
- "do" pub struct Do /// `do`
"dyn" pub struct Dyn /// `dyn`
"else" pub struct Else /// `else`
"enum" pub struct Enum /// `enum`
@@ -597,12 +595,10 @@
(box) => { $crate::token::Box };
(break) => { $crate::token::Break };
(Self) => { $crate::token::CapSelf };
- (catch) => { $crate::token::Catch };
(const) => { $crate::token::Const };
(continue) => { $crate::token::Continue };
(crate) => { $crate::token::Crate };
(default) => { $crate::token::Default };
- (do) => { $crate::token::Do };
(dyn) => { $crate::token::Dyn };
(else) => { $crate::token::Else };
(enum) => { $crate::token::Enum };
@@ -712,12 +708,10 @@
($i:expr, box) => { call!($i, <$crate::token::Box as $crate::synom::Synom>::parse) };
($i:expr, break) => { call!($i, <$crate::token::Break as $crate::synom::Synom>::parse) };
($i:expr, Self) => { call!($i, <$crate::token::CapSelf as $crate::synom::Synom>::parse) };
- ($i:expr, catch) => { call!($i, <$crate::token::Catch as $crate::synom::Synom>::parse) };
($i:expr, const) => { call!($i, <$crate::token::Const as $crate::synom::Synom>::parse) };
($i:expr, continue) => { call!($i, <$crate::token::Continue as $crate::synom::Synom>::parse) };
($i:expr, crate) => { call!($i, <$crate::token::Crate as $crate::synom::Synom>::parse) };
($i:expr, default) => { call!($i, <$crate::token::Default as $crate::synom::Synom>::parse) };
- ($i:expr, do) => { call!($i, <$crate::token::Do as $crate::synom::Synom>::parse) };
($i:expr, dyn) => { call!($i, <$crate::token::Dyn as $crate::synom::Synom>::parse) };
($i:expr, else) => { call!($i, <$crate::token::Else as $crate::synom::Synom>::parse) };
($i:expr, enum) => { call!($i, <$crate::token::Enum as $crate::synom::Synom>::parse) };