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 p.eat(MUT_KW); // TODO: validator to forbid const mut
name(p); name(p);
p.expect(COLON); p.expect(COLON);
types::ty(p); types::type_(p);
p.expect(EQ); p.expect(EQ);
expressions::expr(p); expressions::expr(p);
p.expect(SEMI); p.expect(SEMI);

View file

@ -247,7 +247,7 @@ fn type_item(p: &mut Parser) {
type_params::where_clause(p); type_params::where_clause(p);
p.expect(EQ); p.expect(EQ);
types::ty(p); types::type_(p);
p.expect(SEMI); p.expect(SEMI);
} }

View file

@ -89,7 +89,7 @@ fn named_fields(p: &mut Parser) {
if p.at(IDENT) { if p.at(IDENT) {
name(p); name(p);
p.expect(COLON); p.expect(COLON);
types::ty(p); types::type_(p);
field.complete(p, NAMED_FIELD); field.complete(p, NAMED_FIELD);
} else { } else {
field.abandon(p); field.abandon(p);
@ -105,7 +105,7 @@ fn pos_fields(p: &mut Parser) {
while !p.at(R_PAREN) && !p.at(EOF) { while !p.at(R_PAREN) && !p.at(EOF) {
let pos_field = p.start(); let pos_field = p.start();
visibility(p); visibility(p);
types::ty(p); types::type_(p);
pos_field.complete(p, POS_FIELD); pos_field.complete(p, POS_FIELD);
if !p.at(R_PAREN) { if !p.at(R_PAREN) {

View file

@ -62,7 +62,7 @@ pub(super) fn list(p: &mut Parser) {
} }
} }
if p.at(EQ) { if p.at(EQ) {
types::ty(p) types::type_(p)
} }
m.complete(p, TYPE_PARAM); m.complete(p, TYPE_PARAM);
} }

View file

@ -1,8 +1,9 @@
use super::*; use super::*;
pub(super) fn ty(p: &mut Parser) { pub(super) fn type_(p: &mut Parser) {
match p.current() { 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), IDENT => path_type(p),
_ => { _ => {
p.error("expected type"); 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)); assert!(p.at(L_PAREN));
let m = p.start(); let m = p.start();
p.bump(); p.bump();
@ -18,7 +19,7 @@ fn paren_or_tuple_ty(p: &mut Parser) {
let mut trailing_comma: bool = false; let mut trailing_comma: bool = false;
while !p.at(EOF) && !p.at(R_PAREN) { while !p.at(EOF) && !p.at(R_PAREN) {
n_types += 1; n_types += 1;
ty(p); type_(p);
if p.eat(COMMA) { if p.eat(COMMA) {
trailing_comma = true; trailing_comma = true;
} else { } else {
@ -43,6 +44,15 @@ fn paren_or_tuple_ty(p: &mut Parser) {
m.complete(p, kind); 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) { fn path_type(p: &mut Parser) {
assert!(p.at(IDENT)); assert!(p.at(IDENT));
let m = p.start(); 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)