aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grammar.ron2
-rw-r--r--src/parser/grammar/types.rs33
-rw-r--r--src/syntax_kinds.rs4
-rw-r--r--tests/data/parser/inline/0023_array_type_missing_semi.rs1
-rw-r--r--tests/data/parser/inline/0023_array_type_missing_semi.txt28
-rw-r--r--tests/data/parser/inline/0024_array_type.rs1
-rw-r--r--tests/data/parser/inline/0024_array_type.txt21
-rw-r--r--tests/data/parser/inline/0025_slice_type.rs1
-rw-r--r--tests/data/parser/inline/0025_slice_type.txt17
9 files changed, 108 insertions, 0 deletions
diff --git a/grammar.ron b/grammar.ron
index b43b58f02..bc7dd7c55 100644
--- a/grammar.ron
+++ b/grammar.ron
@@ -106,6 +106,8 @@ Grammar(
106 "NEVER_TYPE", 106 "NEVER_TYPE",
107 "PATH_TYPE", 107 "PATH_TYPE",
108 "POINTER_TYPE", 108 "POINTER_TYPE",
109 "ARRAY_TYPE",
110 "SLICE_TYPE",
109 111
110 "EXTERN_BLOCK", 112 "EXTERN_BLOCK",
111 "ENUM_VARIANT", 113 "ENUM_VARIANT",
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs
index ceadf5f96..4eb333b54 100644
--- a/src/parser/grammar/types.rs
+++ b/src/parser/grammar/types.rs
@@ -5,6 +5,7 @@ pub(super) fn type_(p: &mut Parser) {
5 L_PAREN => paren_or_tuple_type(p), 5 L_PAREN => paren_or_tuple_type(p),
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 IDENT => path_type(p), 9 IDENT => path_type(p),
9 _ => { 10 _ => {
10 p.error("expected type"); 11 p.error("expected type");
@@ -82,6 +83,38 @@ fn pointer_type(p: &mut Parser) {
82 m.complete(p, POINTER_TYPE); 83 m.complete(p, POINTER_TYPE);
83} 84}
84 85
86fn array_or_slice_type(p: &mut Parser) {
87 assert!(p.at(L_BRACK));
88 let m = p.start();
89 p.bump();
90
91 type_(p);
92 let kind = match p.current() {
93 // test slice_type
94 // type T = [()];
95 R_BRACK => {
96 p.bump();
97 SLICE_TYPE
98 },
99
100 // test array_type
101 // type T = [(); 92];
102 SEMI => {
103 p.bump();
104 expressions::expr(p);
105 p.expect(R_BRACK);
106 ARRAY_TYPE
107 }
108 // test array_type_missing_semi
109 // type T = [() 92];
110 _ => {
111 p.error("expected `;` or `]`");
112 SLICE_TYPE
113 }
114 };
115 m.complete(p, kind);
116}
117
85fn path_type(p: &mut Parser) { 118fn path_type(p: &mut Parser) {
86 assert!(p.at(IDENT)); 119 assert!(p.at(IDENT));
87 let m = p.start(); 120 let m = p.start();
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index 181dcc63b..54200f2d1 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -104,6 +104,8 @@ pub enum SyntaxKind {
104 NEVER_TYPE, 104 NEVER_TYPE,
105 PATH_TYPE, 105 PATH_TYPE,
106 POINTER_TYPE, 106 POINTER_TYPE,
107 ARRAY_TYPE,
108 SLICE_TYPE,
107 EXTERN_BLOCK, 109 EXTERN_BLOCK,
108 ENUM_VARIANT, 110 ENUM_VARIANT,
109 NAMED_FIELD, 111 NAMED_FIELD,
@@ -234,6 +236,8 @@ impl SyntaxKind {
234 NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, 236 NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" },
235 PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, 237 PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" },
236 POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, 238 POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" },
239 ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" },
240 SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" },
237 EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, 241 EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
238 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, 242 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
239 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, 243 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
diff --git a/tests/data/parser/inline/0023_array_type_missing_semi.rs b/tests/data/parser/inline/0023_array_type_missing_semi.rs
new file mode 100644
index 000000000..a94851443
--- /dev/null
+++ b/tests/data/parser/inline/0023_array_type_missing_semi.rs
@@ -0,0 +1 @@
type T = [() 92];
diff --git a/tests/data/parser/inline/0023_array_type_missing_semi.txt b/tests/data/parser/inline/0023_array_type_missing_semi.txt
new file mode 100644
index 000000000..bb30a2a2a
--- /dev/null
+++ b/tests/data/parser/inline/0023_array_type_missing_semi.txt
@@ -0,0 +1,28 @@
1FILE@[0; 18)
2 TYPE_ITEM@[0; 13)
3 TYPE_KW@[0; 4)
4 NAME@[4; 7)
5 WHITESPACE@[4; 5)
6 IDENT@[5; 6) "T"
7 WHITESPACE@[6; 7)
8 EQ@[7; 8)
9 SLICE_TYPE@[8; 13)
10 WHITESPACE@[8; 9)
11 L_BRACK@[9; 10)
12 TUPLE_TYPE@[10; 13)
13 L_PAREN@[10; 11)
14 R_PAREN@[11; 12)
15 WHITESPACE@[12; 13)
16 err: `expected `;` or `]``
17 err: `expected SEMI`
18 ERROR@[13; 15)
19 err: `expected item`
20 INT_NUMBER@[13; 15)
21 ERROR@[15; 16)
22 err: `expected item`
23 R_BRACK@[15; 16)
24 ERROR@[16; 18)
25 err: `expected item, found `;`
26consider removing this semicolon`
27 SEMI@[16; 17)
28 WHITESPACE@[17; 18)
diff --git a/tests/data/parser/inline/0024_array_type.rs b/tests/data/parser/inline/0024_array_type.rs
new file mode 100644
index 000000000..27eb22f22
--- /dev/null
+++ b/tests/data/parser/inline/0024_array_type.rs
@@ -0,0 +1 @@
type T = [(); 92];
diff --git a/tests/data/parser/inline/0024_array_type.txt b/tests/data/parser/inline/0024_array_type.txt
new file mode 100644
index 000000000..970734a19
--- /dev/null
+++ b/tests/data/parser/inline/0024_array_type.txt
@@ -0,0 +1,21 @@
1FILE@[0; 19)
2 TYPE_ITEM@[0; 19)
3 TYPE_KW@[0; 4)
4 NAME@[4; 7)
5 WHITESPACE@[4; 5)
6 IDENT@[5; 6) "T"
7 WHITESPACE@[6; 7)
8 EQ@[7; 8)
9 ARRAY_TYPE@[8; 17)
10 WHITESPACE@[8; 9)
11 L_BRACK@[9; 10)
12 TUPLE_TYPE@[10; 12)
13 L_PAREN@[10; 11)
14 R_PAREN@[11; 12)
15 SEMI@[12; 13)
16 LITERAL@[13; 16)
17 WHITESPACE@[13; 14)
18 INT_NUMBER@[14; 16)
19 R_BRACK@[16; 17)
20 SEMI@[17; 18)
21 WHITESPACE@[18; 19)
diff --git a/tests/data/parser/inline/0025_slice_type.rs b/tests/data/parser/inline/0025_slice_type.rs
new file mode 100644
index 000000000..4da1af827
--- /dev/null
+++ b/tests/data/parser/inline/0025_slice_type.rs
@@ -0,0 +1 @@
type T = [()];
diff --git a/tests/data/parser/inline/0025_slice_type.txt b/tests/data/parser/inline/0025_slice_type.txt
new file mode 100644
index 000000000..22938e5e1
--- /dev/null
+++ b/tests/data/parser/inline/0025_slice_type.txt
@@ -0,0 +1,17 @@
1FILE@[0; 15)
2 TYPE_ITEM@[0; 15)
3 TYPE_KW@[0; 4)
4 NAME@[4; 7)
5 WHITESPACE@[4; 5)
6 IDENT@[5; 6) "T"
7 WHITESPACE@[6; 7)
8 EQ@[7; 8)
9 SLICE_TYPE@[8; 13)
10 WHITESPACE@[8; 9)
11 L_BRACK@[9; 10)
12 TUPLE_TYPE@[10; 12)
13 L_PAREN@[10; 11)
14 R_PAREN@[11; 12)
15 R_BRACK@[12; 13)
16 SEMI@[13; 14)
17 WHITESPACE@[14; 15)