From 281c9eeaff8eac4e666089f80f67cf684e1d001b Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Thu, 6 Jun 2019 15:36:16 +0400 Subject: [#1083] Try block syntax --- crates/ra_parser/src/grammar/expressions/atom.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser/src/grammar') diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 8b1a1de49..0df47d33d 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -52,6 +52,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = CONTINUE_KW, LIFETIME, ASYNC_KW, + TRY_KW, ]); const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; @@ -75,6 +76,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![loop] => loop_expr(p, None), T![for] => for_expr(p, None), T![while] => while_expr(p, None), + T![try] => try_expr(p, None), LIFETIME if la == T![:] => { let m = p.start(); label(p); @@ -116,7 +118,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar } }; let blocklike = match done.kind() { - IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR => BlockLike::Block, + IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => BlockLike::Block, _ => BlockLike::NotBlock, }; Some((done, blocklike)) @@ -491,3 +493,17 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { } m.complete(p, BREAK_EXPR) } + +// test try_expr +// fn foo() { +// try { +// +// } +// } +fn try_expr(p: &mut Parser, m: Option) -> CompletedMarker { + assert!(p.at(T![try])); + let m = m.unwrap_or_else(|| p.start()); + p.bump(); + block(p); + m.complete(p, TRY_EXPR) +} -- cgit v1.2.3