aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron2
-rw-r--r--src/grammar/expressions/atom.rs47
-rw-r--r--src/syntax_kinds/generated.rs4
-rw-r--r--tests/data/parser/inline/0085_for_expr.rs3
-rw-r--r--tests/data/parser/inline/0085_for_expr.txt34
-rw-r--r--tests/data/parser/inline/0086_array_expr.rs6
-rw-r--r--tests/data/parser/inline/0086_array_expr.txt54
7 files changed, 150 insertions, 0 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index df769bba6..ca37eb80b 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -140,12 +140,14 @@ Grammar(
140 140
141 // atoms 141 // atoms
142 "TUPLE_EXPR", 142 "TUPLE_EXPR",
143 "ARRAY_EXPR",
143 "PAREN_EXPR", 144 "PAREN_EXPR",
144 "PATH_EXPR", 145 "PATH_EXPR",
145 "LAMBDA_EXPR", 146 "LAMBDA_EXPR",
146 "IF_EXPR", 147 "IF_EXPR",
147 "WHILE_EXPR", 148 "WHILE_EXPR",
148 "LOOP_EXPR", 149 "LOOP_EXPR",
150 "FOR_EXPR",
149 "BLOCK_EXPR", 151 "BLOCK_EXPR",
150 "RETURN_EXPR", 152 "RETURN_EXPR",
151 "MATCH_EXPR", 153 "MATCH_EXPR",
diff --git a/src/grammar/expressions/atom.rs b/src/grammar/expressions/atom.rs
index 65b9e5ef0..e4f681c17 100644
--- a/src/grammar/expressions/atom.rs
+++ b/src/grammar/expressions/atom.rs
@@ -44,11 +44,13 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
44 let la = p.nth(1); 44 let la = p.nth(1);
45 let done = match p.current() { 45 let done = match p.current() {
46 L_PAREN => tuple_expr(p), 46 L_PAREN => tuple_expr(p),
47 L_BRACK => array_expr(p),
47 PIPE => lambda_expr(p), 48 PIPE => lambda_expr(p),
48 MOVE_KW if la == PIPE => lambda_expr(p), 49 MOVE_KW if la == PIPE => lambda_expr(p),
49 IF_KW => if_expr(p), 50 IF_KW => if_expr(p),
50 WHILE_KW => while_expr(p), 51 WHILE_KW => while_expr(p),
51 LOOP_KW => loop_expr(p), 52 LOOP_KW => loop_expr(p),
53 FOR_KW => for_expr(p),
52 MATCH_KW => match_expr(p), 54 MATCH_KW => match_expr(p),
53 UNSAFE_KW if la == L_CURLY => block_expr(p), 55 UNSAFE_KW if la == L_CURLY => block_expr(p),
54 L_CURLY => block_expr(p), 56 L_CURLY => block_expr(p),
@@ -86,6 +88,36 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
86 m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR }) 88 m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR })
87} 89}
88 90
91// test array_expr
92// fn foo() {
93// [];
94// [1];
95// [1, 2,];
96// [1; 2];
97// }
98fn array_expr(p: &mut Parser) -> CompletedMarker {
99 assert!(p.at(L_BRACK));
100 let m = p.start();
101 p.bump();
102 if p.eat(R_BRACK) {
103 return m.complete(p, ARRAY_EXPR);
104 }
105 expr(p);
106 if p.eat(SEMI) {
107 expr(p);
108 p.expect(R_BRACK);
109 return m.complete(p, ARRAY_EXPR);
110 }
111 while !p.at(EOF) && !p.at(R_BRACK) {
112 p.expect(COMMA);
113 if !p.at(R_BRACK) {
114 expr(p);
115 }
116 }
117 p.expect(R_BRACK);
118 m.complete(p, ARRAY_EXPR)
119}
120
89// test lambda_expr 121// test lambda_expr
90// fn foo() { 122// fn foo() {
91// || (); 123// || ();
@@ -156,6 +188,21 @@ fn loop_expr(p: &mut Parser) -> CompletedMarker {
156 m.complete(p, LOOP_EXPR) 188 m.complete(p, LOOP_EXPR)
157} 189}
158 190
191// test for_expr
192// fn foo() {
193// for x in [] {};
194// }
195fn for_expr(p: &mut Parser) -> CompletedMarker {
196 assert!(p.at(FOR_KW));
197 let m = p.start();
198 p.bump();
199 patterns::pattern(p);
200 p.expect(IN_KW);
201 expr_no_struct(p);
202 block(p);
203 m.complete(p, FOR_EXPR)
204}
205
159// test cond 206// test cond
160// fn foo() { if let Some(_) = None {} } 207// fn foo() { if let Some(_) = None {} }
161fn cond(p: &mut Parser) { 208fn cond(p: &mut Parser) {
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 1bce34443..3c5071126 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -130,12 +130,14 @@ pub enum SyntaxKind {
130 STRUCT_PAT, 130 STRUCT_PAT,
131 TUPLE_PAT, 131 TUPLE_PAT,
132 TUPLE_EXPR, 132 TUPLE_EXPR,
133 ARRAY_EXPR,
133 PAREN_EXPR, 134 PAREN_EXPR,
134 PATH_EXPR, 135 PATH_EXPR,
135 LAMBDA_EXPR, 136 LAMBDA_EXPR,
136 IF_EXPR, 137 IF_EXPR,
137 WHILE_EXPR, 138 WHILE_EXPR,
138 LOOP_EXPR, 139 LOOP_EXPR,
140 FOR_EXPR,
139 BLOCK_EXPR, 141 BLOCK_EXPR,
140 RETURN_EXPR, 142 RETURN_EXPR,
141 MATCH_EXPR, 143 MATCH_EXPR,
@@ -361,12 +363,14 @@ impl SyntaxKind {
361 STRUCT_PAT => &SyntaxInfo { name: "STRUCT_PAT" }, 363 STRUCT_PAT => &SyntaxInfo { name: "STRUCT_PAT" },
362 TUPLE_PAT => &SyntaxInfo { name: "TUPLE_PAT" }, 364 TUPLE_PAT => &SyntaxInfo { name: "TUPLE_PAT" },
363 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" }, 365 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" },
366 ARRAY_EXPR => &SyntaxInfo { name: "ARRAY_EXPR" },
364 PAREN_EXPR => &SyntaxInfo { name: "PAREN_EXPR" }, 367 PAREN_EXPR => &SyntaxInfo { name: "PAREN_EXPR" },
365 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" }, 368 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" },
366 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" }, 369 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" },
367 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" }, 370 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" },
368 WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" }, 371 WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" },
369 LOOP_EXPR => &SyntaxInfo { name: "LOOP_EXPR" }, 372 LOOP_EXPR => &SyntaxInfo { name: "LOOP_EXPR" },
373 FOR_EXPR => &SyntaxInfo { name: "FOR_EXPR" },
370 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" }, 374 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" },
371 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" }, 375 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" },
372 MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" }, 376 MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" },
diff --git a/tests/data/parser/inline/0085_for_expr.rs b/tests/data/parser/inline/0085_for_expr.rs
new file mode 100644
index 000000000..972197d2a
--- /dev/null
+++ b/tests/data/parser/inline/0085_for_expr.rs
@@ -0,0 +1,3 @@
1fn foo() {
2 for x in [] {};
3}
diff --git a/tests/data/parser/inline/0085_for_expr.txt b/tests/data/parser/inline/0085_for_expr.txt
new file mode 100644
index 000000000..33dc86ca0
--- /dev/null
+++ b/tests/data/parser/inline/0085_for_expr.txt
@@ -0,0 +1,34 @@
1FILE@[0; 33)
2 FN_ITEM@[0; 33)
3 FN_KW@[0; 2)
4 NAME@[2; 6)
5 WHITESPACE@[2; 3)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 9)
8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9)
11 BLOCK_EXPR@[9; 33)
12 L_CURLY@[9; 10)
13 EXPR_STMT@[10; 31)
14 FOR_EXPR@[10; 29)
15 WHITESPACE@[10; 15)
16 FOR_KW@[15; 18)
17 BIND_PAT@[18; 21)
18 NAME@[18; 21)
19 WHITESPACE@[18; 19)
20 IDENT@[19; 20) "x"
21 WHITESPACE@[20; 21)
22 IN_KW@[21; 23)
23 ARRAY_EXPR@[23; 27)
24 WHITESPACE@[23; 24)
25 L_BRACK@[24; 25)
26 R_BRACK@[25; 26)
27 WHITESPACE@[26; 27)
28 BLOCK_EXPR@[27; 29)
29 L_CURLY@[27; 28)
30 R_CURLY@[28; 29)
31 SEMI@[29; 30)
32 WHITESPACE@[30; 31)
33 R_CURLY@[31; 32)
34 WHITESPACE@[32; 33)
diff --git a/tests/data/parser/inline/0086_array_expr.rs b/tests/data/parser/inline/0086_array_expr.rs
new file mode 100644
index 000000000..4dc1999d1
--- /dev/null
+++ b/tests/data/parser/inline/0086_array_expr.rs
@@ -0,0 +1,6 @@
1fn foo() {
2 [];
3 [1];
4 [1, 2,];
5 [1; 2];
6}
diff --git a/tests/data/parser/inline/0086_array_expr.txt b/tests/data/parser/inline/0086_array_expr.txt
new file mode 100644
index 000000000..40a9b018c
--- /dev/null
+++ b/tests/data/parser/inline/0086_array_expr.txt
@@ -0,0 +1,54 @@
1FILE@[0; 55)
2 FN_ITEM@[0; 55)
3 FN_KW@[0; 2)
4 NAME@[2; 6)
5 WHITESPACE@[2; 3)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 9)
8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9)
11 BLOCK_EXPR@[9; 55)
12 L_CURLY@[9; 10)
13 EXPR_STMT@[10; 23)
14 ARRAY_EXPR@[10; 17)
15 WHITESPACE@[10; 15)
16 L_BRACK@[15; 16)
17 R_BRACK@[16; 17)
18 SEMI@[17; 18)
19 WHITESPACE@[18; 23)
20 EXPR_STMT@[23; 32)
21 ARRAY_EXPR@[23; 26)
22 L_BRACK@[23; 24)
23 LITERAL@[24; 25)
24 INT_NUMBER@[24; 25) "1"
25 R_BRACK@[25; 26)
26 SEMI@[26; 27)
27 WHITESPACE@[27; 32)
28 EXPR_STMT@[32; 45)
29 ARRAY_EXPR@[32; 39)
30 L_BRACK@[32; 33)
31 LITERAL@[33; 34)
32 INT_NUMBER@[33; 34) "1"
33 COMMA@[34; 35)
34 LITERAL@[35; 37)
35 WHITESPACE@[35; 36)
36 INT_NUMBER@[36; 37) "2"
37 COMMA@[37; 38)
38 R_BRACK@[38; 39)
39 SEMI@[39; 40)
40 WHITESPACE@[40; 45)
41 EXPR_STMT@[45; 53)
42 ARRAY_EXPR@[45; 51)
43 L_BRACK@[45; 46)
44 LITERAL@[46; 47)
45 INT_NUMBER@[46; 47) "1"
46 SEMI@[47; 48)
47 LITERAL@[48; 50)
48 WHITESPACE@[48; 49)
49 INT_NUMBER@[49; 50) "2"
50 R_BRACK@[50; 51)
51 SEMI@[51; 52)
52 WHITESPACE@[52; 53)
53 R_CURLY@[53; 54)
54 WHITESPACE@[54; 55)