aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
authorAndrey Tkachenko <[email protected]>2019-06-06 12:36:16 +0100
committerAndrey Tkachenko <[email protected]>2019-06-06 12:43:26 +0100
commit281c9eeaff8eac4e666089f80f67cf684e1d001b (patch)
treed5d315543cfc7aa47db24aafec3b98df3754ddb3 /crates/ra_parser
parentb79e6294a68fd41f0a3dbd9eb907dfe99646d77e (diff)
[#1083] Try block syntax
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs18
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs7
2 files changed, 24 insertions, 1 deletions
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 =
52 CONTINUE_KW, 52 CONTINUE_KW,
53 LIFETIME, 53 LIFETIME,
54 ASYNC_KW, 54 ASYNC_KW,
55 TRY_KW,
55 ]); 56 ]);
56 57
57const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; 58const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
@@ -75,6 +76,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
75 T![loop] => loop_expr(p, None), 76 T![loop] => loop_expr(p, None),
76 T![for] => for_expr(p, None), 77 T![for] => for_expr(p, None),
77 T![while] => while_expr(p, None), 78 T![while] => while_expr(p, None),
79 T![try] => try_expr(p, None),
78 LIFETIME if la == T![:] => { 80 LIFETIME if la == T![:] => {
79 let m = p.start(); 81 let m = p.start();
80 label(p); 82 label(p);
@@ -116,7 +118,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
116 } 118 }
117 }; 119 };
118 let blocklike = match done.kind() { 120 let blocklike = match done.kind() {
119 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR => BlockLike::Block, 121 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => BlockLike::Block,
120 _ => BlockLike::NotBlock, 122 _ => BlockLike::NotBlock,
121 }; 123 };
122 Some((done, blocklike)) 124 Some((done, blocklike))
@@ -491,3 +493,17 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
491 } 493 }
492 m.complete(p, BREAK_EXPR) 494 m.complete(p, BREAK_EXPR)
493} 495}
496
497// test try_expr
498// fn foo() {
499// try {
500//
501// }
502// }
503fn try_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
504 assert!(p.at(T![try]));
505 let m = m.unwrap_or_else(|| p.start());
506 p.bump();
507 block(p);
508 m.complete(p, TRY_EXPR)
509}
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 {
103 LET_KW, 103 LET_KW,
104 MOVE_KW, 104 MOVE_KW,
105 RETURN_KW, 105 RETURN_KW,
106 TRY_KW,
106 AUTO_KW, 107 AUTO_KW,
107 DEFAULT_KW, 108 DEFAULT_KW,
108 UNION_KW, 109 UNION_KW,
@@ -184,6 +185,7 @@ pub enum SyntaxKind {
184 STRUCT_LIT, 185 STRUCT_LIT,
185 NAMED_FIELD_LIST, 186 NAMED_FIELD_LIST,
186 NAMED_FIELD, 187 NAMED_FIELD,
188 TRY_BLOCK_EXPR,
187 CALL_EXPR, 189 CALL_EXPR,
188 INDEX_EXPR, 190 INDEX_EXPR,
189 METHOD_CALL_EXPR, 191 METHOD_CALL_EXPR,
@@ -331,6 +333,7 @@ macro_rules! T {
331 (let) => { $crate::SyntaxKind::LET_KW }; 333 (let) => { $crate::SyntaxKind::LET_KW };
332 (move) => { $crate::SyntaxKind::MOVE_KW }; 334 (move) => { $crate::SyntaxKind::MOVE_KW };
333 (return) => { $crate::SyntaxKind::RETURN_KW }; 335 (return) => { $crate::SyntaxKind::RETURN_KW };
336 (try) => { $crate::SyntaxKind::TRY_KW };
334 (auto) => { $crate::SyntaxKind::AUTO_KW }; 337 (auto) => { $crate::SyntaxKind::AUTO_KW };
335 (default) => { $crate::SyntaxKind::DEFAULT_KW }; 338 (default) => { $crate::SyntaxKind::DEFAULT_KW };
336 (union) => { $crate::SyntaxKind::UNION_KW }; 339 (union) => { $crate::SyntaxKind::UNION_KW };
@@ -388,6 +391,7 @@ impl SyntaxKind {
388 | LET_KW 391 | LET_KW
389 | MOVE_KW 392 | MOVE_KW
390 | RETURN_KW 393 | RETURN_KW
394 | TRY_KW
391 | AUTO_KW 395 | AUTO_KW
392 | DEFAULT_KW 396 | DEFAULT_KW
393 | UNION_KW 397 | UNION_KW
@@ -559,6 +563,7 @@ impl SyntaxKind {
559 LET_KW => &SyntaxInfo { name: "LET_KW" }, 563 LET_KW => &SyntaxInfo { name: "LET_KW" },
560 MOVE_KW => &SyntaxInfo { name: "MOVE_KW" }, 564 MOVE_KW => &SyntaxInfo { name: "MOVE_KW" },
561 RETURN_KW => &SyntaxInfo { name: "RETURN_KW" }, 565 RETURN_KW => &SyntaxInfo { name: "RETURN_KW" },
566 TRY_KW => &SyntaxInfo { name: "TRY_KW" },
562 AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, 567 AUTO_KW => &SyntaxInfo { name: "AUTO_KW" },
563 DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, 568 DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" },
564 UNION_KW => &SyntaxInfo { name: "UNION_KW" }, 569 UNION_KW => &SyntaxInfo { name: "UNION_KW" },
@@ -640,6 +645,7 @@ impl SyntaxKind {
640 STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" }, 645 STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" },
641 NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" }, 646 NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" },
642 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, 647 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
648 TRY_BLOCK_EXPR => &SyntaxInfo { name: "TRY_BLOCK_EXPR" },
643 CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, 649 CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" },
644 INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, 650 INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" },
645 METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, 651 METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" },
@@ -734,6 +740,7 @@ impl SyntaxKind {
734 "let" => LET_KW, 740 "let" => LET_KW,
735 "move" => MOVE_KW, 741 "move" => MOVE_KW,
736 "return" => RETURN_KW, 742 "return" => RETURN_KW,
743 "try" => TRY_KW,
737 _ => return None, 744 _ => return None,
738 }; 745 };
739 Some(kw) 746 Some(kw)