From 2389cf96dd07d8c94da349b10f6f2b750707dfd9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 11 Feb 2018 11:01:00 +0300 Subject: G: Never type --- src/parser/grammar/items/consts.rs | 2 +- src/parser/grammar/items/mod.rs | 2 +- src/parser/grammar/items/structs.rs | 4 ++-- src/parser/grammar/type_params.rs | 2 +- src/parser/grammar/types.rs | 18 ++++++++++++++---- 5 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src/parser/grammar') diff --git a/src/parser/grammar/items/consts.rs b/src/parser/grammar/items/consts.rs index 5f3cf58c2..d6c3753b3 100644 --- a/src/parser/grammar/items/consts.rs +++ b/src/parser/grammar/items/consts.rs @@ -14,7 +14,7 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) { p.eat(MUT_KW); // TODO: validator to forbid const mut name(p); p.expect(COLON); - types::ty(p); + types::type_(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 f1776e0e2..b1edf2f22 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -247,7 +247,7 @@ fn type_item(p: &mut Parser) { type_params::where_clause(p); p.expect(EQ); - types::ty(p); + types::type_(p); p.expect(SEMI); } diff --git a/src/parser/grammar/items/structs.rs b/src/parser/grammar/items/structs.rs index ad18fd270..c72b50808 100644 --- a/src/parser/grammar/items/structs.rs +++ b/src/parser/grammar/items/structs.rs @@ -89,7 +89,7 @@ fn named_fields(p: &mut Parser) { if p.at(IDENT) { name(p); p.expect(COLON); - types::ty(p); + types::type_(p); field.complete(p, NAMED_FIELD); } else { field.abandon(p); @@ -105,7 +105,7 @@ fn pos_fields(p: &mut Parser) { while !p.at(R_PAREN) && !p.at(EOF) { let pos_field = p.start(); visibility(p); - types::ty(p); + types::type_(p); pos_field.complete(p, POS_FIELD); if !p.at(R_PAREN) { diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index 2462b260e..9ea08a55c 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs @@ -62,7 +62,7 @@ pub(super) fn list(p: &mut Parser) { } } if p.at(EQ) { - types::ty(p) + types::type_(p) } m.complete(p, TYPE_PARAM); } diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 71801d8ef..2ae583bd1 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -1,8 +1,9 @@ use super::*; -pub(super) fn ty(p: &mut Parser) { +pub(super) fn type_(p: &mut Parser) { match p.current() { - L_PAREN => paren_or_tuple_ty(p), + L_PAREN => paren_or_tuple_type(p), + EXCL => never_type(p), IDENT => path_type(p), _ => { p.error("expected type"); @@ -10,7 +11,7 @@ pub(super) fn ty(p: &mut Parser) { } } -fn paren_or_tuple_ty(p: &mut Parser) { +fn paren_or_tuple_type(p: &mut Parser) { assert!(p.at(L_PAREN)); let m = p.start(); p.bump(); @@ -18,7 +19,7 @@ fn paren_or_tuple_ty(p: &mut Parser) { let mut trailing_comma: bool = false; while !p.at(EOF) && !p.at(R_PAREN) { n_types += 1; - ty(p); + type_(p); if p.eat(COMMA) { trailing_comma = true; } else { @@ -43,6 +44,15 @@ fn paren_or_tuple_ty(p: &mut Parser) { m.complete(p, kind); } +// test never_type +// type Never = !; +fn never_type(p: &mut Parser) { + assert!(p.at(EXCL)); + let m = p.start(); + p.bump(); + m.complete(p, NEVER_TYPE); +} + fn path_type(p: &mut Parser) { assert!(p.at(IDENT)); let m = p.start(); -- cgit v1.2.3