diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-23 10:37:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-23 10:37:30 +0000 |
| commit | fd1fcf2c2e90ab04103a6aa9d033ec64dcc8d555 (patch) | |
| tree | 31b5facb6a7a24a113e32fd6afa76f326ab8e3a2 /crates/parser/src | |
| parent | b0d81d98dbc4cea6920793c7e2952a0d38ec543e (diff) | |
| parent | bdd8c0b68f097c7d1a65a5b85b94f0a79affa506 (diff) | |
| download | rust-fd1fcf2c2e90ab04103a6aa9d033ec64dcc8d555.tar.gz rust-fd1fcf2c2e90ab04103a6aa9d033ec64dcc8d555.zip | |
Merge #7010
7010: Update ungrammar for const block patterns r=matklad a=Veykril Fixes #6848 Adds const blocks and const block patterns to the AST and parses them. Blocked on https://github.com/rust-analyzer/ungrammar/pull/17/, will merge that PR there once this one gets the OK so I can remove the local ungrammar dependency path and fix the Cargo.lock. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Diffstat (limited to 'crates/parser/src')
| -rw-r--r-- | crates/parser/src/grammar/expressions/atom.rs | 9 | ||||
| -rw-r--r-- | crates/parser/src/grammar/items.rs | 7 | ||||
| -rw-r--r-- | crates/parser/src/grammar/patterns.rs | 14 | ||||
| -rw-r--r-- | crates/parser/src/syntax_kind/generated.rs | 1 |
4 files changed, 29 insertions, 2 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index e897d5a52f0..c7a3556a775 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -46,6 +46,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = T![continue], T![async], T![try], + T![const], T![loop], T![for], LIFETIME_IDENT, @@ -115,6 +116,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar block_expr(p); m.complete(p, EFFECT_EXPR) } + // test const_block + // fn f() { const { } } + T![const] if la == T!['{'] => { + let m = p.start(); + p.bump(T![const]); + block_expr(p); + m.complete(p, EFFECT_EXPR) + } T!['{'] => { // test for_range_from // fn foo() { diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 8999829b437..72b73f89174 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -96,7 +96,10 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { let mut has_mods = false; // modifiers - has_mods |= p.eat(T![const]); + if p.at(T![const]) && p.nth(1) != T!['{'] { + p.eat(T![const]); + has_mods = true; + } // test_err async_without_semicolon // fn foo() { let _ = async {} } @@ -167,7 +170,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { m.complete(p, TRAIT); } - T![const] => { + T![const] if p.nth(1) != T!['{'] => { consts::konst(p, m); } diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index 7e7f73deeac..b53d5749f42 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs @@ -89,6 +89,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { let m = match p.nth(0) { T![box] => box_pat(p), T![ref] | T![mut] => ident_pat(p, true), + T![const] => const_block_pat(p), IDENT => match p.nth(1) { // Checks the token after an IDENT to see if a pattern is a path (Struct { .. }) or macro // (T![x]). @@ -386,3 +387,16 @@ fn box_pat(p: &mut Parser) -> CompletedMarker { pattern_single(p); m.complete(p, BOX_PAT) } + +// test const_block_pat +// fn main() { +// let const { 15 } = (); +// let const { foo(); bar() } = (); +// } +fn const_block_pat(p: &mut Parser) -> CompletedMarker { + assert!(p.at(T![const])); + let m = p.start(); + p.bump(T![const]); + expressions::block_expr(p); + m.complete(p, CONST_BLOCK_PAT) +} diff --git a/crates/parser/src/syntax_kind/generated.rs b/crates/parser/src/syntax_kind/generated.rs index 980aa59794f..f69e71bdba6 100644 --- a/crates/parser/src/syntax_kind/generated.rs +++ b/crates/parser/src/syntax_kind/generated.rs @@ -170,6 +170,7 @@ pub enum SyntaxKind { RANGE_PAT, LITERAL_PAT, MACRO_PAT, + CONST_BLOCK_PAT, TUPLE_EXPR, ARRAY_EXPR, PAREN_EXPR, |
