Skip to content

Commit 03a9bba

Browse files
committed
Parse ConstBlockPat
1 parent be72604 commit 03a9bba

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

crates/parser/src/grammar/patterns.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! FIXME: write short doc here
22
3+
use expressions::block_expr;
4+
35
use super::*;
46

57
pub(super) const PATTERN_FIRST: TokenSet =
@@ -89,6 +91,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
8991
let m = match p.nth(0) {
9092
T![box] => box_pat(p),
9193
T![ref] | T![mut] => ident_pat(p, true),
94+
T![const] => const_block_pat(p),
9295
IDENT => match p.nth(1) {
9396
// Checks the token after an IDENT to see if a pattern is a path (Struct { .. }) or macro
9497
// (T![x]).
@@ -386,3 +389,16 @@ fn box_pat(p: &mut Parser) -> CompletedMarker {
386389
pattern_single(p);
387390
m.complete(p, BOX_PAT)
388391
}
392+
393+
// test const_block_pat
394+
// fn main() {
395+
// let const { 15 } = ();
396+
// let const { foo(); bar() } = ();
397+
// }
398+
fn const_block_pat(p: &mut Parser) -> CompletedMarker {
399+
assert!(p.at(T![const]));
400+
let m = p.start();
401+
p.bump(T![const]);
402+
block_expr(p);
403+
m.complete(p, CONST_BLOCK_PAT)
404+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let const { 15 } = ();
3+
let const { foo(); bar() } = ();
4+
}

0 commit comments

Comments
 (0)