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 ++++++++++++++---- tests/data/parser/inline/0020_never_type.rs | 1 + tests/data/parser/inline/0020_never_type.txt | 13 +++++++++++++ 7 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 tests/data/parser/inline/0020_never_type.rs create mode 100644 tests/data/parser/inline/0020_never_type.txt 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(); diff --git a/tests/data/parser/inline/0020_never_type.rs b/tests/data/parser/inline/0020_never_type.rs new file mode 100644 index 000000000..de399fcf4 --- /dev/null +++ b/tests/data/parser/inline/0020_never_type.rs @@ -0,0 +1 @@ +type Never = !; diff --git a/tests/data/parser/inline/0020_never_type.txt b/tests/data/parser/inline/0020_never_type.txt new file mode 100644 index 000000000..935f33459 --- /dev/null +++ b/tests/data/parser/inline/0020_never_type.txt @@ -0,0 +1,13 @@ +FILE@[0; 16) + TYPE_ITEM@[0; 16) + TYPE_KW@[0; 4) + NAME@[4; 11) + WHITESPACE@[4; 5) + IDENT@[5; 10) "Never" + WHITESPACE@[10; 11) + EQ@[11; 12) + NEVER_TYPE@[12; 14) + WHITESPACE@[12; 13) + EXCL@[13; 14) + SEMI@[14; 15) + WHITESPACE@[15; 16) -- cgit v1.2.3