From 2a2815266b35de12bd3c48cc405e8b3e8fcf8885 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 15:35:59 +0300 Subject: refactor ascription --- src/parser/grammar/items/consts.rs | 3 +-- src/parser/grammar/items/mod.rs | 4 ++-- src/parser/grammar/types.rs | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/parser/grammar') diff --git a/src/parser/grammar/items/consts.rs b/src/parser/grammar/items/consts.rs index d6c3753b3..ca26a7814 100644 --- a/src/parser/grammar/items/consts.rs +++ b/src/parser/grammar/items/consts.rs @@ -13,8 +13,7 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) { p.bump(); p.eat(MUT_KW); // TODO: validator to forbid const mut name(p); - p.expect(COLON); - types::type_(p); + types::ascription(p); p.expect(EQ); expressions::expr(p); p.expect(SEMI); diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index 00c52dc09..0d9eccd2f 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -279,8 +279,8 @@ fn fn_item(p: &mut Parser) { let m = p.start(); p.bump(); patterns::pattern(p); - if p.eat(COLON) { - types::type_(p); + if p.at(COLON) { + types::ascription(p); } if p.eat(EQ) { expressions::expr(p); diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index bcdc3ef97..014086521 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -17,6 +17,11 @@ pub(super) fn type_(p: &mut Parser) { } } +pub(super) fn ascription(p: &mut Parser) { + p.expect(COLON); + type_(p) +} + fn type_no_plus(p: &mut Parser) { type_(p); } -- cgit v1.2.3