diff options
Diffstat (limited to 'src/parser/grammar/expressions.rs')
-rw-r--r-- | src/parser/grammar/expressions.rs | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/parser/grammar/expressions.rs b/src/parser/grammar/expressions.rs index 3956df568..5b18e2294 100644 --- a/src/parser/grammar/expressions.rs +++ b/src/parser/grammar/expressions.rs | |||
@@ -154,5 +154,42 @@ fn path_expr(p: &mut Parser) -> CompletedMarker { | |||
154 | assert!(paths::is_path_start(p)); | 154 | assert!(paths::is_path_start(p)); |
155 | let m = p.start(); | 155 | let m = p.start(); |
156 | paths::expr_path(p); | 156 | paths::expr_path(p); |
157 | m.complete(p, PATH_EXPR) | 157 | if p.at(L_CURLY) { |
158 | struct_lit(p); | ||
159 | m.complete(p, STRUCT_LIT) | ||
160 | } else { | ||
161 | m.complete(p, PATH_EXPR) | ||
162 | } | ||
163 | } | ||
164 | |||
165 | // test struct_lit | ||
166 | // fn foo() { | ||
167 | // S {}; | ||
168 | // S { x, y: 32, }; | ||
169 | // S { x, y: 32, ..Default::default() }; | ||
170 | // } | ||
171 | fn struct_lit(p: &mut Parser) { | ||
172 | assert!(p.at(L_CURLY)); | ||
173 | p.bump(); | ||
174 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
175 | match p.current() { | ||
176 | IDENT => { | ||
177 | let m = p.start(); | ||
178 | name_ref(p); | ||
179 | if p.eat(COLON) { | ||
180 | expr(p); | ||
181 | } | ||
182 | m.complete(p, STRUCT_LIT_FIELD); | ||
183 | }, | ||
184 | DOTDOT => { | ||
185 | p.bump(); | ||
186 | expr(p); | ||
187 | }, | ||
188 | _ => p.err_and_bump("expected identifier"), | ||
189 | } | ||
190 | if !p.at(R_CURLY) { | ||
191 | p.expect(COMMA); | ||
192 | } | ||
193 | } | ||
194 | p.expect(R_CURLY); | ||
158 | } | 195 | } |