G: Never type

This commit is contained in:
Aleksey Kladov 2018-02-11 11:01:00 +03:00
parent e19d038a0e
commit 2389cf96dd
7 changed files with 33 additions and 9 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -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();

View File

@ -0,0 +1 @@
type Never = !;

View File

@ -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)