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 +++++++++++++++++- crates/ra_parser/src/syntax_kind/generated.rs | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser') 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) +} diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index d7926bd91..2c021f3e9 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -103,6 +103,7 @@ pub enum SyntaxKind { LET_KW, MOVE_KW, RETURN_KW, + TRY_KW, AUTO_KW, DEFAULT_KW, UNION_KW, @@ -184,6 +185,7 @@ pub enum SyntaxKind { STRUCT_LIT, NAMED_FIELD_LIST, NAMED_FIELD, + TRY_BLOCK_EXPR, CALL_EXPR, INDEX_EXPR, METHOD_CALL_EXPR, @@ -331,6 +333,7 @@ macro_rules! T { (let) => { $crate::SyntaxKind::LET_KW }; (move) => { $crate::SyntaxKind::MOVE_KW }; (return) => { $crate::SyntaxKind::RETURN_KW }; + (try) => { $crate::SyntaxKind::TRY_KW }; (auto) => { $crate::SyntaxKind::AUTO_KW }; (default) => { $crate::SyntaxKind::DEFAULT_KW }; (union) => { $crate::SyntaxKind::UNION_KW }; @@ -388,6 +391,7 @@ impl SyntaxKind { | LET_KW | MOVE_KW | RETURN_KW + | TRY_KW | AUTO_KW | DEFAULT_KW | UNION_KW @@ -559,6 +563,7 @@ impl SyntaxKind { LET_KW => &SyntaxInfo { name: "LET_KW" }, MOVE_KW => &SyntaxInfo { name: "MOVE_KW" }, RETURN_KW => &SyntaxInfo { name: "RETURN_KW" }, + TRY_KW => &SyntaxInfo { name: "TRY_KW" }, AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, UNION_KW => &SyntaxInfo { name: "UNION_KW" }, @@ -640,6 +645,7 @@ impl SyntaxKind { STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" }, NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" }, NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, + TRY_BLOCK_EXPR => &SyntaxInfo { name: "TRY_BLOCK_EXPR" }, CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, @@ -734,6 +740,7 @@ impl SyntaxKind { "let" => LET_KW, "move" => MOVE_KW, "return" => RETURN_KW, + "try" => TRY_KW, _ => return None, }; Some(kw) -- cgit v1.2.3