diff options
Diffstat (limited to 'crates/ra_parser')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 6 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions.rs | 1 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 18 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 7 |
4 files changed, 27 insertions, 5 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index cf603eba1..5997636d6 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs | |||
@@ -87,10 +87,8 @@ pub(crate) fn pattern(p: &mut Parser) { | |||
87 | } | 87 | } |
88 | 88 | ||
89 | pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { | 89 | pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { |
90 | let with_semi = match with_semi { | 90 | let with_semi = |
91 | true => expressions::StmtWithSemi::Yes, | 91 | if with_semi { expressions::StmtWithSemi::Yes } else { expressions::StmtWithSemi::No }; |
92 | false => expressions::StmtWithSemi::No, | ||
93 | }; | ||
94 | 92 | ||
95 | expressions::stmt(p, with_semi) | 93 | expressions::stmt(p, with_semi) |
96 | } | 94 | } |
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index bb6c78b5f..99e32c4e8 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -454,6 +454,7 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | |||
454 | // x.1i32; | 454 | // x.1i32; |
455 | // x.0x01; | 455 | // x.0x01; |
456 | // } | 456 | // } |
457 | #[allow(clippy::if_same_then_else)] | ||
457 | fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | 458 | fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { |
458 | assert!(p.at(T![.])); | 459 | assert!(p.at(T![.])); |
459 | let m = lhs.precede(p); | 460 | let m = lhs.precede(p); |
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 8b1a1de49..725fb99f6 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 | ||
57 | const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; | 58 | 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 | |||
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_block_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,9 @@ 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 => { |
122 | BlockLike::Block | ||
123 | } | ||
120 | _ => BlockLike::NotBlock, | 124 | _ => BlockLike::NotBlock, |
121 | }; | 125 | }; |
122 | Some((done, blocklike)) | 126 | Some((done, blocklike)) |
@@ -491,3 +495,15 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { | |||
491 | } | 495 | } |
492 | m.complete(p, BREAK_EXPR) | 496 | m.complete(p, BREAK_EXPR) |
493 | } | 497 | } |
498 | |||
499 | // test try_block_expr | ||
500 | // fn foo() { | ||
501 | // let _ = try {}; | ||
502 | // } | ||
503 | fn try_block_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) |