diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-11 09:58:32 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-11 09:58:32 +0000 |
commit | 7176029803fe2e00f29ab7d20a384e3ee6f53ba3 (patch) | |
tree | 51e7251231162d5d31b6e18fabdbb466ffb94d19 | |
parent | e19d038a0e1d9af8270450c5fe8fbbdf0f15cb24 (diff) | |
parent | 96437b050f2743fef2e37eaab7259f2f98f9b473 (diff) |
Merge #48
48: Types r=matklad a=matklad
bors r+
31 files changed, 488 insertions, 34 deletions
diff --git a/grammar.ron b/grammar.ron index 41d48f7b2..d5ad59553 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -105,6 +105,12 @@ Grammar( | |||
105 | "TUPLE_TYPE", | 105 | "TUPLE_TYPE", |
106 | "NEVER_TYPE", | 106 | "NEVER_TYPE", |
107 | "PATH_TYPE", | 107 | "PATH_TYPE", |
108 | "POINTER_TYPE", | ||
109 | "ARRAY_TYPE", | ||
110 | "SLICE_TYPE", | ||
111 | "REFERENCE_TYPE", | ||
112 | "PLACEHOLDER_TYPE", | ||
113 | "FN_POINTER_TYPE", | ||
108 | 114 | ||
109 | "EXTERN_BLOCK", | 115 | "EXTERN_BLOCK", |
110 | "ENUM_VARIANT", | 116 | "ENUM_VARIANT", |
diff --git a/src/parser/grammar/items/consts.rs b/src/parser/grammar/items/consts.rs index 5f3cf58c2..d6c3753b3 100644 --- a/src/parser/grammar/items/consts.rs +++ b/src/parser/grammar/items/consts.rs | |||
@@ -14,7 +14,7 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) { | |||
14 | p.eat(MUT_KW); // TODO: validator to forbid const mut | 14 | p.eat(MUT_KW); // TODO: validator to forbid const mut |
15 | name(p); | 15 | name(p); |
16 | p.expect(COLON); | 16 | p.expect(COLON); |
17 | types::ty(p); | 17 | types::type_(p); |
18 | p.expect(EQ); | 18 | p.expect(EQ); |
19 | expressions::expr(p); | 19 | expressions::expr(p); |
20 | p.expect(SEMI); | 20 | p.expect(SEMI); |
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index f1776e0e2..18ee8af86 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -222,12 +222,6 @@ fn fn_item(p: &mut Parser) { | |||
222 | p.expect(L_CURLY); | 222 | p.expect(L_CURLY); |
223 | p.expect(R_CURLY); | 223 | p.expect(R_CURLY); |
224 | } | 224 | } |
225 | |||
226 | fn fn_value_parameters(p: &mut Parser) { | ||
227 | assert!(p.at(L_PAREN)); | ||
228 | p.bump(); | ||
229 | p.expect(R_PAREN); | ||
230 | } | ||
231 | } | 225 | } |
232 | 226 | ||
233 | // test type_item | 227 | // test type_item |
@@ -247,7 +241,7 @@ fn type_item(p: &mut Parser) { | |||
247 | type_params::where_clause(p); | 241 | type_params::where_clause(p); |
248 | 242 | ||
249 | p.expect(EQ); | 243 | p.expect(EQ); |
250 | types::ty(p); | 244 | types::type_(p); |
251 | p.expect(SEMI); | 245 | p.expect(SEMI); |
252 | } | 246 | } |
253 | 247 | ||
@@ -263,14 +257,3 @@ fn mod_item(p: &mut Parser) { | |||
263 | } | 257 | } |
264 | } | 258 | } |
265 | } | 259 | } |
266 | |||
267 | fn abi(p: &mut Parser) { | ||
268 | assert!(p.at(EXTERN_KW)); | ||
269 | let abi = p.start(); | ||
270 | p.bump(); | ||
271 | match p.current() { | ||
272 | STRING | RAW_STRING => p.bump(), | ||
273 | _ => (), | ||
274 | } | ||
275 | abi.complete(p, ABI); | ||
276 | } | ||
diff --git a/src/parser/grammar/items/structs.rs b/src/parser/grammar/items/structs.rs index ad18fd270..c72b50808 100644 --- a/src/parser/grammar/items/structs.rs +++ b/src/parser/grammar/items/structs.rs | |||
@@ -89,7 +89,7 @@ fn named_fields(p: &mut Parser) { | |||
89 | if p.at(IDENT) { | 89 | if p.at(IDENT) { |
90 | name(p); | 90 | name(p); |
91 | p.expect(COLON); | 91 | p.expect(COLON); |
92 | types::ty(p); | 92 | types::type_(p); |
93 | field.complete(p, NAMED_FIELD); | 93 | field.complete(p, NAMED_FIELD); |
94 | } else { | 94 | } else { |
95 | field.abandon(p); | 95 | field.abandon(p); |
@@ -105,7 +105,7 @@ fn pos_fields(p: &mut Parser) { | |||
105 | while !p.at(R_PAREN) && !p.at(EOF) { | 105 | while !p.at(R_PAREN) && !p.at(EOF) { |
106 | let pos_field = p.start(); | 106 | let pos_field = p.start(); |
107 | visibility(p); | 107 | visibility(p); |
108 | types::ty(p); | 108 | types::type_(p); |
109 | pos_field.complete(p, POS_FIELD); | 109 | pos_field.complete(p, POS_FIELD); |
110 | 110 | ||
111 | if !p.at(R_PAREN) { | 111 | if !p.at(R_PAREN) { |
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs index abf9fe86c..5266354c1 100644 --- a/src/parser/grammar/mod.rs +++ b/src/parser/grammar/mod.rs | |||
@@ -50,6 +50,30 @@ fn alias(p: &mut Parser) -> bool { | |||
50 | true //FIXME: return false if three are errors | 50 | true //FIXME: return false if three are errors |
51 | } | 51 | } |
52 | 52 | ||
53 | fn abi(p: &mut Parser) { | ||
54 | assert!(p.at(EXTERN_KW)); | ||
55 | let abi = p.start(); | ||
56 | p.bump(); | ||
57 | match p.current() { | ||
58 | STRING | RAW_STRING => p.bump(), | ||
59 | _ => (), | ||
60 | } | ||
61 | abi.complete(p, ABI); | ||
62 | } | ||
63 | |||
64 | fn fn_value_parameters(p: &mut Parser) { | ||
65 | assert!(p.at(L_PAREN)); | ||
66 | p.bump(); | ||
67 | p.expect(R_PAREN); | ||
68 | } | ||
69 | |||
70 | fn fn_ret_type(p: &mut Parser) { | ||
71 | if p.at(THIN_ARROW) { | ||
72 | p.bump(); | ||
73 | types::type_(p); | ||
74 | } | ||
75 | } | ||
76 | |||
53 | fn name(p: &mut Parser) { | 77 | fn name(p: &mut Parser) { |
54 | if p.at(IDENT) { | 78 | if p.at(IDENT) { |
55 | let m = p.start(); | 79 | let m = p.start(); |
diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index 2462b260e..9ea08a55c 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs | |||
@@ -62,7 +62,7 @@ pub(super) fn list(p: &mut Parser) { | |||
62 | } | 62 | } |
63 | } | 63 | } |
64 | if p.at(EQ) { | 64 | if p.at(EQ) { |
65 | types::ty(p) | 65 | types::type_(p) |
66 | } | 66 | } |
67 | m.complete(p, TYPE_PARAM); | 67 | m.complete(p, TYPE_PARAM); |
68 | } | 68 | } |
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 71801d8ef..a4967a00a 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs | |||
@@ -1,8 +1,14 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn ty(p: &mut Parser) { | 3 | pub(super) fn type_(p: &mut Parser) { |
4 | match p.current() { | 4 | match p.current() { |
5 | L_PAREN => paren_or_tuple_ty(p), | 5 | L_PAREN => paren_or_tuple_type(p), |
6 | EXCL => never_type(p), | ||
7 | STAR => pointer_type(p), | ||
8 | L_BRACK => array_or_slice_type(p), | ||
9 | AMPERSAND => reference_type(p), | ||
10 | UNDERSCORE => placeholder_type(p), | ||
11 | FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), | ||
6 | IDENT => path_type(p), | 12 | IDENT => path_type(p), |
7 | _ => { | 13 | _ => { |
8 | p.error("expected type"); | 14 | p.error("expected type"); |
@@ -10,7 +16,11 @@ pub(super) fn ty(p: &mut Parser) { | |||
10 | } | 16 | } |
11 | } | 17 | } |
12 | 18 | ||
13 | fn paren_or_tuple_ty(p: &mut Parser) { | 19 | fn type_no_plus(p: &mut Parser) { |
20 | type_(p); | ||
21 | } | ||
22 | |||
23 | fn paren_or_tuple_type(p: &mut Parser) { | ||
14 | assert!(p.at(L_PAREN)); | 24 | assert!(p.at(L_PAREN)); |
15 | let m = p.start(); | 25 | let m = p.start(); |
16 | p.bump(); | 26 | p.bump(); |
@@ -18,7 +28,7 @@ fn paren_or_tuple_ty(p: &mut Parser) { | |||
18 | let mut trailing_comma: bool = false; | 28 | let mut trailing_comma: bool = false; |
19 | while !p.at(EOF) && !p.at(R_PAREN) { | 29 | while !p.at(EOF) && !p.at(R_PAREN) { |
20 | n_types += 1; | 30 | n_types += 1; |
21 | ty(p); | 31 | type_(p); |
22 | if p.eat(COMMA) { | 32 | if p.eat(COMMA) { |
23 | trailing_comma = true; | 33 | trailing_comma = true; |
24 | } else { | 34 | } else { |
@@ -43,6 +53,119 @@ fn paren_or_tuple_ty(p: &mut Parser) { | |||
43 | m.complete(p, kind); | 53 | m.complete(p, kind); |
44 | } | 54 | } |
45 | 55 | ||
56 | // test never_type | ||
57 | // type Never = !; | ||
58 | fn never_type(p: &mut Parser) { | ||
59 | assert!(p.at(EXCL)); | ||
60 | let m = p.start(); | ||
61 | p.bump(); | ||
62 | m.complete(p, NEVER_TYPE); | ||
63 | } | ||
64 | |||
65 | fn pointer_type(p: &mut Parser) { | ||
66 | assert!(p.at(STAR)); | ||
67 | let m = p.start(); | ||
68 | p.bump(); | ||
69 | |||
70 | match p.current() { | ||
71 | // test pointer_type_mut | ||
72 | // type M = *mut (); | ||
73 | // type C = *mut (); | ||
74 | MUT_KW | CONST_KW => p.bump(), | ||
75 | _ => { | ||
76 | // test pointer_type_no_mutability | ||
77 | // type T = *(); | ||
78 | p.error( | ||
79 | "expected mut or const in raw pointer type \ | ||
80 | (use `*mut T` or `*const T` as appropriate)", | ||
81 | ); | ||
82 | } | ||
83 | }; | ||
84 | |||
85 | type_no_plus(p); | ||
86 | m.complete(p, POINTER_TYPE); | ||
87 | } | ||
88 | |||
89 | fn array_or_slice_type(p: &mut Parser) { | ||
90 | assert!(p.at(L_BRACK)); | ||
91 | let m = p.start(); | ||
92 | p.bump(); | ||
93 | |||
94 | type_(p); | ||
95 | let kind = match p.current() { | ||
96 | // test slice_type | ||
97 | // type T = [()]; | ||
98 | R_BRACK => { | ||
99 | p.bump(); | ||
100 | SLICE_TYPE | ||
101 | } | ||
102 | |||
103 | // test array_type | ||
104 | // type T = [(); 92]; | ||
105 | SEMI => { | ||
106 | p.bump(); | ||
107 | expressions::expr(p); | ||
108 | p.expect(R_BRACK); | ||
109 | ARRAY_TYPE | ||
110 | } | ||
111 | // test array_type_missing_semi | ||
112 | // type T = [() 92]; | ||
113 | _ => { | ||
114 | p.error("expected `;` or `]`"); | ||
115 | SLICE_TYPE | ||
116 | } | ||
117 | }; | ||
118 | m.complete(p, kind); | ||
119 | } | ||
120 | |||
121 | // test reference_type; | ||
122 | // type A = &(); | ||
123 | // type B = &'static (); | ||
124 | // type C = &mut (); | ||
125 | fn reference_type(p: &mut Parser) { | ||
126 | assert!(p.at(AMPERSAND)); | ||
127 | let m = p.start(); | ||
128 | p.bump(); | ||
129 | p.eat(LIFETIME); | ||
130 | p.eat(MUT_KW); | ||
131 | type_no_plus(p); | ||
132 | m.complete(p, REFERENCE_TYPE); | ||
133 | } | ||
134 | |||
135 | // test placeholder_type | ||
136 | // type Placeholder = _; | ||
137 | fn placeholder_type(p: &mut Parser) { | ||
138 | assert!(p.at(UNDERSCORE)); | ||
139 | let m = p.start(); | ||
140 | p.bump(); | ||
141 | m.complete(p, PLACEHOLDER_TYPE); | ||
142 | } | ||
143 | |||
144 | // test fn_pointer_type | ||
145 | // type A = fn(); | ||
146 | // type B = unsafe fn(); | ||
147 | // type C = unsafe extern "C" fn(); | ||
148 | fn fn_pointer_type(p: &mut Parser) { | ||
149 | let m = p.start(); | ||
150 | p.eat(UNSAFE_KW); | ||
151 | if p.at(EXTERN_KW) { | ||
152 | abi(p); | ||
153 | } | ||
154 | // test fn_pointer_type_missing_fn | ||
155 | // type F = unsafe (); | ||
156 | if !p.eat(FN_KW) { | ||
157 | m.abandon(p); | ||
158 | p.error("expected `fn`"); | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | fn_value_parameters(p); | ||
163 | // test fn_pointer_type_with_ret | ||
164 | // type F = fn() -> (); | ||
165 | fn_ret_type(p); | ||
166 | m.complete(p, FN_POINTER_TYPE); | ||
167 | } | ||
168 | |||
46 | fn path_type(p: &mut Parser) { | 169 | fn path_type(p: &mut Parser) { |
47 | assert!(p.at(IDENT)); | 170 | assert!(p.at(IDENT)); |
48 | let m = p.start(); | 171 | let m = p.start(); |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 630d3d2a5..db0f51beb 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -103,6 +103,12 @@ pub enum SyntaxKind { | |||
103 | TUPLE_TYPE, | 103 | TUPLE_TYPE, |
104 | NEVER_TYPE, | 104 | NEVER_TYPE, |
105 | PATH_TYPE, | 105 | PATH_TYPE, |
106 | POINTER_TYPE, | ||
107 | ARRAY_TYPE, | ||
108 | SLICE_TYPE, | ||
109 | REFERENCE_TYPE, | ||
110 | PLACEHOLDER_TYPE, | ||
111 | FN_POINTER_TYPE, | ||
106 | EXTERN_BLOCK, | 112 | EXTERN_BLOCK, |
107 | ENUM_VARIANT, | 113 | ENUM_VARIANT, |
108 | NAMED_FIELD, | 114 | NAMED_FIELD, |
@@ -232,6 +238,12 @@ impl SyntaxKind { | |||
232 | TUPLE_TYPE => &SyntaxInfo { name: "TUPLE_TYPE" }, | 238 | TUPLE_TYPE => &SyntaxInfo { name: "TUPLE_TYPE" }, |
233 | NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, | 239 | NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, |
234 | PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, | 240 | PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, |
241 | POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, | ||
242 | ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" }, | ||
243 | SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" }, | ||
244 | REFERENCE_TYPE => &SyntaxInfo { name: "REFERENCE_TYPE" }, | ||
245 | PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" }, | ||
246 | FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, | ||
235 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 247 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
236 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 248 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
237 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 249 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
diff --git a/tests/data/parser/inline/0020_never_type.rs b/tests/data/parser/inline/0020_never_type.rs new file mode 100644 index 000000000..de399fcf4 --- /dev/null +++ b/tests/data/parser/inline/0020_never_type.rs | |||
@@ -0,0 +1 @@ | |||
type Never = !; | |||
diff --git a/tests/data/parser/inline/0020_never_type.txt b/tests/data/parser/inline/0020_never_type.txt new file mode 100644 index 000000000..935f33459 --- /dev/null +++ b/tests/data/parser/inline/0020_never_type.txt | |||
@@ -0,0 +1,13 @@ | |||
1 | FILE@[0; 16) | ||
2 | TYPE_ITEM@[0; 16) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 11) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 10) "Never" | ||
7 | WHITESPACE@[10; 11) | ||
8 | EQ@[11; 12) | ||
9 | NEVER_TYPE@[12; 14) | ||
10 | WHITESPACE@[12; 13) | ||
11 | EXCL@[13; 14) | ||
12 | SEMI@[14; 15) | ||
13 | WHITESPACE@[15; 16) | ||
diff --git a/tests/data/parser/inline/0021_pointer_type_no_mutability.rs b/tests/data/parser/inline/0021_pointer_type_no_mutability.rs new file mode 100644 index 000000000..fae705131 --- /dev/null +++ b/tests/data/parser/inline/0021_pointer_type_no_mutability.rs | |||
@@ -0,0 +1 @@ | |||
type T = *(); | |||
diff --git a/tests/data/parser/inline/0021_pointer_type_no_mutability.txt b/tests/data/parser/inline/0021_pointer_type_no_mutability.txt new file mode 100644 index 000000000..f7720a712 --- /dev/null +++ b/tests/data/parser/inline/0021_pointer_type_no_mutability.txt | |||
@@ -0,0 +1,17 @@ | |||
1 | FILE@[0; 14) | ||
2 | TYPE_ITEM@[0; 14) | ||
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 | POINTER_TYPE@[8; 12) | ||
10 | WHITESPACE@[8; 9) | ||
11 | STAR@[9; 10) | ||
12 | err: `expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)` | ||
13 | TUPLE_TYPE@[10; 12) | ||
14 | L_PAREN@[10; 11) | ||
15 | R_PAREN@[11; 12) | ||
16 | SEMI@[12; 13) | ||
17 | WHITESPACE@[13; 14) | ||
diff --git a/tests/data/parser/inline/0022_pointer_type_mut.rs b/tests/data/parser/inline/0022_pointer_type_mut.rs new file mode 100644 index 000000000..04b2bb9ba --- /dev/null +++ b/tests/data/parser/inline/0022_pointer_type_mut.rs | |||
@@ -0,0 +1,2 @@ | |||
1 | type M = *mut (); | ||
2 | type C = *mut (); | ||
diff --git a/tests/data/parser/inline/0022_pointer_type_mut.txt b/tests/data/parser/inline/0022_pointer_type_mut.txt new file mode 100644 index 000000000..c3ab2b887 --- /dev/null +++ b/tests/data/parser/inline/0022_pointer_type_mut.txt | |||
@@ -0,0 +1,35 @@ | |||
1 | FILE@[0; 36) | ||
2 | TYPE_ITEM@[0; 18) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 7) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 6) "M" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | POINTER_TYPE@[8; 16) | ||
10 | WHITESPACE@[8; 9) | ||
11 | STAR@[9; 10) | ||
12 | MUT_KW@[10; 13) | ||
13 | TUPLE_TYPE@[13; 16) | ||
14 | WHITESPACE@[13; 14) | ||
15 | L_PAREN@[14; 15) | ||
16 | R_PAREN@[15; 16) | ||
17 | SEMI@[16; 17) | ||
18 | WHITESPACE@[17; 18) | ||
19 | TYPE_ITEM@[18; 36) | ||
20 | TYPE_KW@[18; 22) | ||
21 | NAME@[22; 25) | ||
22 | WHITESPACE@[22; 23) | ||
23 | IDENT@[23; 24) "C" | ||
24 | WHITESPACE@[24; 25) | ||
25 | EQ@[25; 26) | ||
26 | POINTER_TYPE@[26; 34) | ||
27 | WHITESPACE@[26; 27) | ||
28 | STAR@[27; 28) | ||
29 | MUT_KW@[28; 31) | ||
30 | TUPLE_TYPE@[31; 34) | ||
31 | WHITESPACE@[31; 32) | ||
32 | L_PAREN@[32; 33) | ||
33 | R_PAREN@[33; 34) | ||
34 | SEMI@[34; 35) | ||
35 | WHITESPACE@[35; 36) | ||
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 @@ | |||
1 | FILE@[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 `;` | ||
26 | consider 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 @@ | |||
1 | FILE@[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 @@ | |||
1 | FILE@[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) | ||
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) | ||
diff --git a/tests/data/parser/inline/0027_placeholder_type.rs b/tests/data/parser/inline/0027_placeholder_type.rs new file mode 100644 index 000000000..7952dbd57 --- /dev/null +++ b/tests/data/parser/inline/0027_placeholder_type.rs | |||
@@ -0,0 +1 @@ | |||
type Placeholder = _; | |||
diff --git a/tests/data/parser/inline/0027_placeholder_type.txt b/tests/data/parser/inline/0027_placeholder_type.txt new file mode 100644 index 000000000..ab848836c --- /dev/null +++ b/tests/data/parser/inline/0027_placeholder_type.txt | |||
@@ -0,0 +1,13 @@ | |||
1 | FILE@[0; 22) | ||
2 | TYPE_ITEM@[0; 22) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 17) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 16) "Placeholder" | ||
7 | WHITESPACE@[16; 17) | ||
8 | EQ@[17; 18) | ||
9 | PLACEHOLDER_TYPE@[18; 20) | ||
10 | WHITESPACE@[18; 19) | ||
11 | UNDERSCORE@[19; 20) | ||
12 | SEMI@[20; 21) | ||
13 | WHITESPACE@[21; 22) | ||
diff --git a/tests/data/parser/inline/0028_fn_pointer_type.rs b/tests/data/parser/inline/0028_fn_pointer_type.rs new file mode 100644 index 000000000..c9bf3bdb4 --- /dev/null +++ b/tests/data/parser/inline/0028_fn_pointer_type.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | type A = fn(); | ||
2 | type B = unsafe fn(); | ||
3 | type C = unsafe extern "C" fn(); | ||
diff --git a/tests/data/parser/inline/0028_fn_pointer_type.txt b/tests/data/parser/inline/0028_fn_pointer_type.txt new file mode 100644 index 000000000..6c62b0051 --- /dev/null +++ b/tests/data/parser/inline/0028_fn_pointer_type.txt | |||
@@ -0,0 +1,52 @@ | |||
1 | FILE@[0; 70) | ||
2 | TYPE_ITEM@[0; 15) | ||
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 | FN_POINTER_TYPE@[8; 13) | ||
10 | WHITESPACE@[8; 9) | ||
11 | FN_KW@[9; 11) | ||
12 | L_PAREN@[11; 12) | ||
13 | R_PAREN@[12; 13) | ||
14 | SEMI@[13; 14) | ||
15 | WHITESPACE@[14; 15) | ||
16 | TYPE_ITEM@[15; 37) | ||
17 | TYPE_KW@[15; 19) | ||
18 | NAME@[19; 22) | ||
19 | WHITESPACE@[19; 20) | ||
20 | IDENT@[20; 21) "B" | ||
21 | WHITESPACE@[21; 22) | ||
22 | EQ@[22; 23) | ||
23 | FN_POINTER_TYPE@[23; 35) | ||
24 | WHITESPACE@[23; 24) | ||
25 | UNSAFE_KW@[24; 30) | ||
26 | WHITESPACE@[30; 31) | ||
27 | FN_KW@[31; 33) | ||
28 | L_PAREN@[33; 34) | ||
29 | R_PAREN@[34; 35) | ||
30 | SEMI@[35; 36) | ||
31 | WHITESPACE@[36; 37) | ||
32 | TYPE_ITEM@[37; 70) | ||
33 | TYPE_KW@[37; 41) | ||
34 | NAME@[41; 44) | ||
35 | WHITESPACE@[41; 42) | ||
36 | IDENT@[42; 43) "C" | ||
37 | WHITESPACE@[43; 44) | ||
38 | EQ@[44; 45) | ||
39 | FN_POINTER_TYPE@[45; 68) | ||
40 | WHITESPACE@[45; 46) | ||
41 | UNSAFE_KW@[46; 52) | ||
42 | ABI@[52; 64) | ||
43 | WHITESPACE@[52; 53) | ||
44 | EXTERN_KW@[53; 59) | ||
45 | WHITESPACE@[59; 60) | ||
46 | STRING@[60; 63) | ||
47 | WHITESPACE@[63; 64) | ||
48 | FN_KW@[64; 66) | ||
49 | L_PAREN@[66; 67) | ||
50 | R_PAREN@[67; 68) | ||
51 | SEMI@[68; 69) | ||
52 | WHITESPACE@[69; 70) | ||
diff --git a/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.rs b/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.rs new file mode 100644 index 000000000..f014914ff --- /dev/null +++ b/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.rs | |||
@@ -0,0 +1 @@ | |||
type F = unsafe (); | |||
diff --git a/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.txt b/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.txt new file mode 100644 index 000000000..dd6e24096 --- /dev/null +++ b/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.txt | |||
@@ -0,0 +1,24 @@ | |||
1 | FILE@[0; 20) | ||
2 | TYPE_ITEM@[0; 16) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 7) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 6) "F" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | WHITESPACE@[8; 9) | ||
10 | UNSAFE_KW@[9; 15) | ||
11 | err: `expected `fn`` | ||
12 | err: `expected SEMI` | ||
13 | WHITESPACE@[15; 16) | ||
14 | ERROR@[16; 17) | ||
15 | err: `expected item` | ||
16 | L_PAREN@[16; 17) | ||
17 | ERROR@[17; 18) | ||
18 | err: `expected item` | ||
19 | R_PAREN@[17; 18) | ||
20 | ERROR@[18; 20) | ||
21 | err: `expected item, found `;` | ||
22 | consider removing this semicolon` | ||
23 | SEMI@[18; 19) | ||
24 | WHITESPACE@[19; 20) | ||
diff --git a/tests/data/parser/inline/0030_fn_pointer_type_with_ret.rs b/tests/data/parser/inline/0030_fn_pointer_type_with_ret.rs new file mode 100644 index 000000000..e3ba5e87f --- /dev/null +++ b/tests/data/parser/inline/0030_fn_pointer_type_with_ret.rs | |||
@@ -0,0 +1 @@ | |||
type F = fn() -> (); | |||
diff --git a/tests/data/parser/inline/0030_fn_pointer_type_with_ret.txt b/tests/data/parser/inline/0030_fn_pointer_type_with_ret.txt new file mode 100644 index 000000000..b41efa368 --- /dev/null +++ b/tests/data/parser/inline/0030_fn_pointer_type_with_ret.txt | |||
@@ -0,0 +1,21 @@ | |||
1 | FILE@[0; 21) | ||
2 | TYPE_ITEM@[0; 21) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 7) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 6) "F" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | FN_POINTER_TYPE@[8; 19) | ||
10 | WHITESPACE@[8; 9) | ||
11 | FN_KW@[9; 11) | ||
12 | L_PAREN@[11; 12) | ||
13 | R_PAREN@[12; 13) | ||
14 | WHITESPACE@[13; 14) | ||
15 | THIN_ARROW@[14; 16) | ||
16 | TUPLE_TYPE@[16; 19) | ||
17 | WHITESPACE@[16; 17) | ||
18 | L_PAREN@[17; 18) | ||
19 | R_PAREN@[18; 19) | ||
20 | SEMI@[19; 20) | ||
21 | WHITESPACE@[20; 21) | ||
diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs index b50e70849..ae1dea810 100644 --- a/tests/testutils/src/lib.rs +++ b/tests/testutils/src/lib.rs | |||
@@ -26,21 +26,20 @@ where | |||
26 | F: Fn(&str) -> String, | 26 | F: Fn(&str) -> String, |
27 | { | 27 | { |
28 | for path in collect_tests(paths) { | 28 | for path in collect_tests(paths) { |
29 | let actual = { | 29 | let input_code = read_text(&path); |
30 | let text = read_text(&path); | 30 | let parse_tree = f(&input_code); |
31 | f(&text) | ||
32 | }; | ||
33 | let path = path.with_extension("txt"); | 31 | let path = path.with_extension("txt"); |
34 | if !path.exists() { | 32 | if !path.exists() { |
35 | println!("\nfile: {}", path.display()); | 33 | println!("\nfile: {}", path.display()); |
36 | println!("No .txt file with expected result, creating..."); | 34 | println!("No .txt file with expected result, creating...\n"); |
37 | file::put_text(&path, actual).unwrap(); | 35 | println!("{}\n{}", input_code, parse_tree); |
36 | file::put_text(&path, parse_tree).unwrap(); | ||
38 | panic!("No expected result") | 37 | panic!("No expected result") |
39 | } | 38 | } |
40 | let expected = read_text(&path); | 39 | let expected = read_text(&path); |
41 | let expected = expected.as_str(); | 40 | let expected = expected.as_str(); |
42 | let actual = actual.as_str(); | 41 | let parse_tree = parse_tree.as_str(); |
43 | assert_equal_text(expected, actual, &path); | 42 | assert_equal_text(expected, parse_tree, &path); |
44 | } | 43 | } |
45 | } | 44 | } |
46 | 45 | ||