aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grammar.ron2
-rw-r--r--src/grammar/expressions/atom.rs47
-rw-r--r--src/syntax_kinds/generated.rs4
3 files changed, 53 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" },