aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-11 08:54:09 +0000
committerAleksey Kladov <[email protected]>2018-02-11 08:54:09 +0000
commiteb4c05d572ff0c4e92452232d6591d7a2796e785 (patch)
tree371136f9c2ad04ff1fca3db94e73872988395fa1
parent555c4ae37560493fd901aad41951ad1664043459 (diff)
G: reference types
-rw-r--r--grammar.ron1
-rw-r--r--src/parser/grammar/types.rs15
-rw-r--r--src/syntax_kinds.rs2
-rw-r--r--tests/data/parser/inline/0026_reference_type;.rs3
-rw-r--r--tests/data/parser/inline/0026_reference_type;.txt50
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 ();
123fn 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
118fn path_type(p: &mut Parser) { 133fn 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 @@
1type A = &();
2type B = &'static ();
3type 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 @@
1FILE@[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)