Support parsing catch expressions.
Fixes #109
diff --git a/src/expr.rs b/src/expr.rs
index 69a3389..3068082 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -176,6 +176,11 @@
/// `expr?`
Try(Box<Expr>),
+
+ /// A catch expression.
+ ///
+ /// E.g. `do catch { block }`
+ Catch(Block),
}
/// A field-value pair in a struct literal.
@@ -427,6 +432,8 @@
|
expr_match
|
+ expr_catch
+ |
call!(expr_closure, allow_struct)
|
cond_reduce!(allow_block, expr_block)
@@ -677,6 +684,13 @@
}))
));
+ named!(expr_catch -> ExprKind, do_parse!(
+ keyword!("do") >>
+ keyword!("catch") >>
+ catch_block: block >>
+ (ExprKind::Catch(catch_block))
+ ));
+
fn arm_requires_comma(arm: &Arm) -> bool {
if let ExprKind::Block(Unsafety::Normal, _) = arm.body.node {
false
@@ -1337,6 +1351,11 @@
tokens.append_all(arms);
tokens.append("}");
}
+ ExprKind::Catch(ref body) => {
+ tokens.append("do");
+ tokens.append("catch");
+ body.to_tokens(tokens);
+ }
ExprKind::Closure(capture, ref decl, ref expr) => {
capture.to_tokens(tokens);
tokens.append("|");