diff options
-rw-r--r-- | grammar.ron | 1 | ||||
-rw-r--r-- | src/parser/grammar/types.rs | 15 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/inline/0026_reference_type;.rs | 3 | ||||
-rw-r--r-- | tests/data/parser/inline/0026_reference_type;.txt | 50 |
5 files changed, 71 insertions, 0 deletions
diff --git a/grammar.ron b/grammar.ron index bc7dd7c55..0905c282a 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -108,6 +108,7 @@ Grammar( | |||
108 | "POINTER_TYPE", | 108 | "POINTER_TYPE", |
109 | "ARRAY_TYPE", | 109 | "ARRAY_TYPE", |
110 | "SLICE_TYPE", | 110 | "SLICE_TYPE", |
111 | "REFERENCE_TYPE", | ||
111 | 112 | ||
112 | "EXTERN_BLOCK", | 113 | "EXTERN_BLOCK", |
113 | "ENUM_VARIANT", | 114 | "ENUM_VARIANT", |
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 4eb333b54..003341db5 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs | |||
@@ -6,6 +6,7 @@ pub(super) fn type_(p: &mut Parser) { | |||
6 | EXCL => never_type(p), | 6 | EXCL => never_type(p), |
7 | STAR => pointer_type(p), | 7 | STAR => pointer_type(p), |
8 | L_BRACK => array_or_slice_type(p), | 8 | L_BRACK => array_or_slice_type(p), |
9 | AMPERSAND => reference_type(p), | ||
9 | IDENT => path_type(p), | 10 | IDENT => path_type(p), |
10 | _ => { | 11 | _ => { |
11 | p.error("expected type"); | 12 | p.error("expected type"); |
@@ -115,6 +116,20 @@ fn array_or_slice_type(p: &mut Parser) { | |||
115 | m.complete(p, kind); | 116 | m.complete(p, kind); |
116 | } | 117 | } |
117 | 118 | ||
119 | // test reference_type; | ||
120 | // type A = &(); | ||
121 | // type B = &'static (); | ||
122 | // type C = &mut (); | ||
123 | fn reference_type(p: &mut Parser) { | ||
124 | assert!(p.at(AMPERSAND)); | ||
125 | let m = p.start(); | ||
126 | p.bump(); | ||
127 | p.eat(LIFETIME); | ||
128 | p.eat(MUT_KW); | ||
129 | type_no_plus(p); | ||
130 | m.complete(p, REFERENCE_TYPE); | ||
131 | } | ||
132 | |||
118 | fn path_type(p: &mut Parser) { | 133 | fn path_type(p: &mut Parser) { |
119 | assert!(p.at(IDENT)); | 134 | assert!(p.at(IDENT)); |
120 | let m = p.start(); | 135 | let m = p.start(); |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 54200f2d1..597550a32 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -106,6 +106,7 @@ pub enum SyntaxKind { | |||
106 | POINTER_TYPE, | 106 | POINTER_TYPE, |
107 | ARRAY_TYPE, | 107 | ARRAY_TYPE, |
108 | SLICE_TYPE, | 108 | SLICE_TYPE, |
109 | REFERENCE_TYPE, | ||
109 | EXTERN_BLOCK, | 110 | EXTERN_BLOCK, |
110 | ENUM_VARIANT, | 111 | ENUM_VARIANT, |
111 | NAMED_FIELD, | 112 | NAMED_FIELD, |
@@ -238,6 +239,7 @@ impl SyntaxKind { | |||
238 | POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, | 239 | POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, |
239 | ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" }, | 240 | ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" }, |
240 | SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" }, | 241 | SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" }, |
242 | REFERENCE_TYPE => &SyntaxInfo { name: "REFERENCE_TYPE" }, | ||
241 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 243 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
242 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 244 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
243 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 245 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
diff --git a/tests/data/parser/inline/0026_reference_type;.rs b/tests/data/parser/inline/0026_reference_type;.rs new file mode 100644 index 000000000..3ac0badab --- /dev/null +++ b/tests/data/parser/inline/0026_reference_type;.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | type A = &(); | ||
2 | type B = &'static (); | ||
3 | type C = &mut (); | ||
diff --git a/tests/data/parser/inline/0026_reference_type;.txt b/tests/data/parser/inline/0026_reference_type;.txt new file mode 100644 index 000000000..665c021e1 --- /dev/null +++ b/tests/data/parser/inline/0026_reference_type;.txt | |||
@@ -0,0 +1,50 @@ | |||
1 | FILE@[0; 54) | ||
2 | TYPE_ITEM@[0; 14) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 7) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 6) "A" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | REFERENCE_TYPE@[8; 12) | ||
10 | WHITESPACE@[8; 9) | ||
11 | AMPERSAND@[9; 10) | ||
12 | TUPLE_TYPE@[10; 12) | ||
13 | L_PAREN@[10; 11) | ||
14 | R_PAREN@[11; 12) | ||
15 | SEMI@[12; 13) | ||
16 | WHITESPACE@[13; 14) | ||
17 | TYPE_ITEM@[14; 36) | ||
18 | TYPE_KW@[14; 18) | ||
19 | NAME@[18; 21) | ||
20 | WHITESPACE@[18; 19) | ||
21 | IDENT@[19; 20) "B" | ||
22 | WHITESPACE@[20; 21) | ||
23 | EQ@[21; 22) | ||
24 | REFERENCE_TYPE@[22; 34) | ||
25 | WHITESPACE@[22; 23) | ||
26 | AMPERSAND@[23; 24) | ||
27 | LIFETIME@[24; 31) "'static" | ||
28 | TUPLE_TYPE@[31; 34) | ||
29 | WHITESPACE@[31; 32) | ||
30 | L_PAREN@[32; 33) | ||
31 | R_PAREN@[33; 34) | ||
32 | SEMI@[34; 35) | ||
33 | WHITESPACE@[35; 36) | ||
34 | TYPE_ITEM@[36; 54) | ||
35 | TYPE_KW@[36; 40) | ||
36 | NAME@[40; 43) | ||
37 | WHITESPACE@[40; 41) | ||
38 | IDENT@[41; 42) "C" | ||
39 | WHITESPACE@[42; 43) | ||
40 | EQ@[43; 44) | ||
41 | REFERENCE_TYPE@[44; 52) | ||
42 | WHITESPACE@[44; 45) | ||
43 | AMPERSAND@[45; 46) | ||
44 | MUT_KW@[46; 49) | ||
45 | TUPLE_TYPE@[49; 52) | ||
46 | WHITESPACE@[49; 50) | ||
47 | L_PAREN@[50; 51) | ||
48 | R_PAREN@[51; 52) | ||
49 | SEMI@[52; 53) | ||
50 | WHITESPACE@[53; 54) | ||