From f843f23abae72ba3bd2920edc2a8635eafb61409 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 15:33:51 +0300 Subject: Type ascription in let --- src/parser/grammar/items/mod.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/parser/grammar') diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index 73fd5235a..00c52dc09 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -267,13 +267,24 @@ fn fn_item(p: &mut Parser) { m.complete(p, BLOCK); } + // test let_stmt; + // fn foo() { + // let a; + // let b: i32; + // let c = 92; + // let d: i32 = 92; + // } fn let_stmt(p: &mut Parser) { assert!(p.at(LET_KW)); let m = p.start(); p.bump(); patterns::pattern(p); - p.expect(EQ); - expressions::expr(p); + if p.eat(COLON) { + types::type_(p); + } + if p.eat(EQ) { + expressions::expr(p); + } p.expect(SEMI); m.complete(p, LET_STMT); } -- cgit v1.2.3