aboutsummaryrefslogtreecommitdiff
path: root/src/grammar/expressions/atom.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/grammar/expressions/atom.rs')
-rw-r--r--src/grammar/expressions/atom.rs47
1 files changed, 47 insertions, 0 deletions
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) {