G: pointer types
This commit is contained in:
parent
2389cf96dd
commit
ceb94ece2a
8 changed files with 94 additions and 8 deletions
|
|
@ -4,6 +4,7 @@ pub(super) fn type_(p: &mut Parser) {
|
|||
match p.current() {
|
||||
L_PAREN => paren_or_tuple_type(p),
|
||||
EXCL => never_type(p),
|
||||
STAR => pointer_type(p),
|
||||
IDENT => path_type(p),
|
||||
_ => {
|
||||
p.error("expected type");
|
||||
|
|
@ -11,6 +12,10 @@ pub(super) fn type_(p: &mut Parser) {
|
|||
}
|
||||
}
|
||||
|
||||
fn type_no_plus(p: &mut Parser) {
|
||||
type_(p);
|
||||
}
|
||||
|
||||
fn paren_or_tuple_type(p: &mut Parser) {
|
||||
assert!(p.at(L_PAREN));
|
||||
let m = p.start();
|
||||
|
|
@ -53,6 +58,30 @@ fn never_type(p: &mut Parser) {
|
|||
m.complete(p, NEVER_TYPE);
|
||||
}
|
||||
|
||||
fn pointer_type(p: &mut Parser) {
|
||||
assert!(p.at(STAR));
|
||||
let m = p.start();
|
||||
p.bump();
|
||||
|
||||
match p.current() {
|
||||
// test pointer_type_mut
|
||||
// type M = *mut ();
|
||||
// type C = *mut ();
|
||||
MUT_KW | CONST_KW => p.bump(),
|
||||
_ => {
|
||||
// test pointer_type_no_mutability
|
||||
// type T = *();
|
||||
p.error(
|
||||
"expected mut or const in raw pointer type \
|
||||
(use `*mut T` or `*const T` as appropriate)"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
type_no_plus(p);
|
||||
m.complete(p, POINTER_TYPE);
|
||||
}
|
||||
|
||||
fn path_type(p: &mut Parser) {
|
||||
assert!(p.at(IDENT));
|
||||
let m = p.start();
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ pub enum SyntaxKind {
|
|||
TUPLE_TYPE,
|
||||
NEVER_TYPE,
|
||||
PATH_TYPE,
|
||||
POINTER_TYPE,
|
||||
EXTERN_BLOCK,
|
||||
ENUM_VARIANT,
|
||||
NAMED_FIELD,
|
||||
|
|
@ -232,6 +233,7 @@ impl SyntaxKind {
|
|||
TUPLE_TYPE => &SyntaxInfo { name: "TUPLE_TYPE" },
|
||||
NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" },
|
||||
PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" },
|
||||
POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" },
|
||||
EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
|
||||
ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
|
||||
NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue