From 9e02e432b570e33b703032f24a4fbb90cb7eb4eb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 12:59:52 +0300 Subject: expr stmt --- src/parser/grammar/items/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index d059833a0..c88e39596 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -223,6 +223,11 @@ fn fn_item(p: &mut Parser) { fn_ret_type(p); block(p); + // test block + // fn a() {} + // fn b() { let _ = 1; } + // fn c() { 1; 2; } + // fn d() { 1; 2 } fn block(p: &mut Parser) { if !p.at(L_CURLY) { p.error("expected block"); @@ -232,7 +237,18 @@ fn fn_item(p: &mut Parser) { while !p.at(EOF) && !p.at(R_CURLY) { match p.current() { LET_KW => let_stmt(p), - _ => p.err_and_bump("expected statement"), + _ => { + let expr_stmt = p.start(); + expressions::expr(p); + if p.eat(SEMI) { + expr_stmt.complete(p, EXPR_STMT); + if p.at(R_CURLY) { + break; + } + } else { + expr_stmt.abandon(p); + } + } } } p.expect(R_CURLY); -- cgit v1.2.3