aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-31 18:38:36 +0100
committerAleksey Kladov <[email protected]>2018-07-31 18:38:36 +0100
commitce3462ce8fed8bb86d887643479c73908fc326a3 (patch)
treef6999e706291b7e39da48259728efd8ec85c848c /src/parser/grammar
parenteba1e8a334a707645701db48fddc61acad7b2dbc (diff)
struct literals
Diffstat (limited to 'src/parser/grammar')
-rw-r--r--src/parser/grammar/expressions.rs39
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// }
171fn 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}