mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
G: reference types
This commit is contained in:
parent
555c4ae375
commit
eb4c05d572
5 changed files with 71 additions and 0 deletions
|
@ -108,6 +108,7 @@ Grammar(
|
||||||
"POINTER_TYPE",
|
"POINTER_TYPE",
|
||||||
"ARRAY_TYPE",
|
"ARRAY_TYPE",
|
||||||
"SLICE_TYPE",
|
"SLICE_TYPE",
|
||||||
|
"REFERENCE_TYPE",
|
||||||
|
|
||||||
"EXTERN_BLOCK",
|
"EXTERN_BLOCK",
|
||||||
"ENUM_VARIANT",
|
"ENUM_VARIANT",
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub(super) fn type_(p: &mut Parser) {
|
||||||
EXCL => never_type(p),
|
EXCL => never_type(p),
|
||||||
STAR => pointer_type(p),
|
STAR => pointer_type(p),
|
||||||
L_BRACK => array_or_slice_type(p),
|
L_BRACK => array_or_slice_type(p),
|
||||||
|
AMPERSAND => reference_type(p),
|
||||||
IDENT => path_type(p),
|
IDENT => path_type(p),
|
||||||
_ => {
|
_ => {
|
||||||
p.error("expected type");
|
p.error("expected type");
|
||||||
|
@ -115,6 +116,20 @@ fn array_or_slice_type(p: &mut Parser) {
|
||||||
m.complete(p, kind);
|
m.complete(p, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test reference_type;
|
||||||
|
// type A = &();
|
||||||
|
// type B = &'static ();
|
||||||
|
// type C = &mut ();
|
||||||
|
fn reference_type(p: &mut Parser) {
|
||||||
|
assert!(p.at(AMPERSAND));
|
||||||
|
let m = p.start();
|
||||||
|
p.bump();
|
||||||
|
p.eat(LIFETIME);
|
||||||
|
p.eat(MUT_KW);
|
||||||
|
type_no_plus(p);
|
||||||
|
m.complete(p, REFERENCE_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();
|
||||||
|
|
|
@ -106,6 +106,7 @@ pub enum SyntaxKind {
|
||||||
POINTER_TYPE,
|
POINTER_TYPE,
|
||||||
ARRAY_TYPE,
|
ARRAY_TYPE,
|
||||||
SLICE_TYPE,
|
SLICE_TYPE,
|
||||||
|
REFERENCE_TYPE,
|
||||||
EXTERN_BLOCK,
|
EXTERN_BLOCK,
|
||||||
ENUM_VARIANT,
|
ENUM_VARIANT,
|
||||||
NAMED_FIELD,
|
NAMED_FIELD,
|
||||||
|
@ -238,6 +239,7 @@ impl SyntaxKind {
|
||||||
POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" },
|
POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" },
|
||||||
ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" },
|
ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" },
|
||||||
SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" },
|
SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" },
|
||||||
|
REFERENCE_TYPE => &SyntaxInfo { name: "REFERENCE_TYPE" },
|
||||||
EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
|
EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
|
||||||
ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
|
ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
|
||||||
NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
|
NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
|
||||||
|
|
3
tests/data/parser/inline/0026_reference_type;.rs
Normal file
3
tests/data/parser/inline/0026_reference_type;.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
type A = &();
|
||||||
|
type B = &'static ();
|
||||||
|
type C = &mut ();
|
50
tests/data/parser/inline/0026_reference_type;.txt
Normal file
50
tests/data/parser/inline/0026_reference_type;.txt
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
FILE@[0; 54)
|
||||||
|
TYPE_ITEM@[0; 14)
|
||||||
|
TYPE_KW@[0; 4)
|
||||||
|
NAME@[4; 7)
|
||||||
|
WHITESPACE@[4; 5)
|
||||||
|
IDENT@[5; 6) "A"
|
||||||
|
WHITESPACE@[6; 7)
|
||||||
|
EQ@[7; 8)
|
||||||
|
REFERENCE_TYPE@[8; 12)
|
||||||
|
WHITESPACE@[8; 9)
|
||||||
|
AMPERSAND@[9; 10)
|
||||||
|
TUPLE_TYPE@[10; 12)
|
||||||
|
L_PAREN@[10; 11)
|
||||||
|
R_PAREN@[11; 12)
|
||||||
|
SEMI@[12; 13)
|
||||||
|
WHITESPACE@[13; 14)
|
||||||
|
TYPE_ITEM@[14; 36)
|
||||||
|
TYPE_KW@[14; 18)
|
||||||
|
NAME@[18; 21)
|
||||||
|
WHITESPACE@[18; 19)
|
||||||
|
IDENT@[19; 20) "B"
|
||||||
|
WHITESPACE@[20; 21)
|
||||||
|
EQ@[21; 22)
|
||||||
|
REFERENCE_TYPE@[22; 34)
|
||||||
|
WHITESPACE@[22; 23)
|
||||||
|
AMPERSAND@[23; 24)
|
||||||
|
LIFETIME@[24; 31) "'static"
|
||||||
|
TUPLE_TYPE@[31; 34)
|
||||||
|
WHITESPACE@[31; 32)
|
||||||
|
L_PAREN@[32; 33)
|
||||||
|
R_PAREN@[33; 34)
|
||||||
|
SEMI@[34; 35)
|
||||||
|
WHITESPACE@[35; 36)
|
||||||
|
TYPE_ITEM@[36; 54)
|
||||||
|
TYPE_KW@[36; 40)
|
||||||
|
NAME@[40; 43)
|
||||||
|
WHITESPACE@[40; 41)
|
||||||
|
IDENT@[41; 42) "C"
|
||||||
|
WHITESPACE@[42; 43)
|
||||||
|
EQ@[43; 44)
|
||||||
|
REFERENCE_TYPE@[44; 52)
|
||||||
|
WHITESPACE@[44; 45)
|
||||||
|
AMPERSAND@[45; 46)
|
||||||
|
MUT_KW@[46; 49)
|
||||||
|
TUPLE_TYPE@[49; 52)
|
||||||
|
WHITESPACE@[49; 50)
|
||||||
|
L_PAREN@[50; 51)
|
||||||
|
R_PAREN@[51; 52)
|
||||||
|
SEMI@[52; 53)
|
||||||
|
WHITESPACE@[53; 54)
|
Loading…
Reference in a new issue