diff options
author | Aleksey Kladov <[email protected]> | 2018-07-31 21:13:08 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-31 21:13:08 +0100 |
commit | d82a21ab202b2f5e8c96847802d806735ec74ad3 (patch) | |
tree | aea23d0bb9760a6104f5994a73b37c869cbaf4bb /src/parser/grammar/items | |
parent | 1af8eb9c08f974a1b3beecfebadeb03144ef337d (diff) |
lambda expressions
Diffstat (limited to 'src/parser/grammar/items')
-rw-r--r-- | src/parser/grammar/items/mod.rs | 63 |
1 files changed, 3 insertions, 60 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index d1da1ecb4..8c2704be5 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -15,7 +15,7 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { | |||
15 | pub(super) const ITEM_FIRST: TokenSet = | 15 | pub(super) const ITEM_FIRST: TokenSet = |
16 | token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, ENUM_KW, FN_KW, PUB_KW, POUND]; | 16 | token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, ENUM_KW, FN_KW, PUB_KW, POUND]; |
17 | 17 | ||
18 | fn item(p: &mut Parser) { | 18 | pub(super) fn item(p: &mut Parser) { |
19 | let item = p.start(); | 19 | let item = p.start(); |
20 | attributes::outer_attributes(p); | 20 | attributes::outer_attributes(p); |
21 | visibility(p); | 21 | visibility(p); |
@@ -239,7 +239,7 @@ fn fn_item(p: &mut Parser) { | |||
239 | type_params::list(p); | 239 | type_params::list(p); |
240 | 240 | ||
241 | if p.at(L_PAREN) { | 241 | if p.at(L_PAREN) { |
242 | fn_value_parameters(p); | 242 | params::list(p); |
243 | } else { | 243 | } else { |
244 | p.error("expected function arguments"); | 244 | p.error("expected function arguments"); |
245 | } | 245 | } |
@@ -252,64 +252,7 @@ fn fn_item(p: &mut Parser) { | |||
252 | // fn foo<T>() where T: Copy {} | 252 | // fn foo<T>() where T: Copy {} |
253 | type_params::where_clause(p); | 253 | type_params::where_clause(p); |
254 | 254 | ||
255 | block(p); | 255 | expressions::block(p); |
256 | |||
257 | // test block | ||
258 | // fn a() {} | ||
259 | // fn b() { let _ = 1; } | ||
260 | // fn c() { 1; 2; } | ||
261 | // fn d() { 1; 2 } | ||
262 | fn block(p: &mut Parser) { | ||
263 | if !p.at(L_CURLY) { | ||
264 | p.error("expected block"); | ||
265 | } | ||
266 | let m = p.start(); | ||
267 | p.bump(); | ||
268 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
269 | match p.current() { | ||
270 | LET_KW => let_stmt(p), | ||
271 | c => { | ||
272 | // test block_items | ||
273 | // fn a() { fn b() {} } | ||
274 | if ITEM_FIRST.contains(c) { | ||
275 | item(p) | ||
276 | } else { | ||
277 | let expr_stmt = p.start(); | ||
278 | expressions::expr(p); | ||
279 | if p.eat(SEMI) { | ||
280 | expr_stmt.complete(p, EXPR_STMT); | ||
281 | } else { | ||
282 | expr_stmt.abandon(p); | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | p.expect(R_CURLY); | ||
289 | m.complete(p, BLOCK); | ||
290 | } | ||
291 | |||
292 | // test let_stmt; | ||
293 | // fn foo() { | ||
294 | // let a; | ||
295 | // let b: i32; | ||
296 | // let c = 92; | ||
297 | // let d: i32 = 92; | ||
298 | // } | ||
299 | fn let_stmt(p: &mut Parser) { | ||
300 | assert!(p.at(LET_KW)); | ||
301 | let m = p.start(); | ||
302 | p.bump(); | ||
303 | patterns::pattern(p); | ||
304 | if p.at(COLON) { | ||
305 | types::ascription(p); | ||
306 | } | ||
307 | if p.eat(EQ) { | ||
308 | expressions::expr(p); | ||
309 | } | ||
310 | p.expect(SEMI); | ||
311 | m.complete(p, LET_STMT); | ||
312 | } | ||
313 | } | 256 | } |
314 | 257 | ||
315 | // test type_item | 258 | // test type_item |