diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-10 09:54:34 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-10 09:54:34 +0000 |
commit | c3b009b6d24225ad2add62fce8206918fceba3eb (patch) | |
tree | 6e68e8242bbc181e5a846754466d4109783b6a2f /src | |
parent | 419b9b7e5efd895249934551cb2588b27a956f58 (diff) | |
parent | dd6e5371ebddeaeecb3d1e2d3d6c8b3c9050bb05 (diff) |
Merge #45
45: Types r=matklad a=matklad
bors r+
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/grammar/items/mod.rs | 80 | ||||
-rw-r--r-- | src/parser/grammar/type_params.rs | 5 | ||||
-rw-r--r-- | src/parser/grammar/types.rs | 11 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 7 |
4 files changed, 74 insertions, 29 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index b73628ec0..ffe86fa97 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -150,7 +150,14 @@ fn item(p: &mut Parser) { | |||
150 | } | 150 | } |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | FN_KW => { | |
154 | fn_item(p); | ||
155 | FN_ITEM | ||
156 | } | ||
157 | TYPE_KW => { | ||
158 | type_item(p); | ||
159 | TYPE_ITEM | ||
160 | } | ||
154 | MOD_KW => { | 161 | MOD_KW => { |
155 | mod_item(p); | 162 | mod_item(p); |
156 | MOD_ITEM | 163 | MOD_ITEM |
@@ -163,10 +170,6 @@ fn item(p: &mut Parser) { | |||
163 | structs::enum_item(p); | 170 | structs::enum_item(p); |
164 | ENUM_ITEM | 171 | ENUM_ITEM |
165 | } | 172 | } |
166 | FN_KW => { | ||
167 | fn_item(p); | ||
168 | FN_ITEM | ||
169 | } | ||
170 | L_CURLY => { | 173 | L_CURLY => { |
171 | item.abandon(p); | 174 | item.abandon(p); |
172 | error_block(p, "expected item"); | 175 | error_block(p, "expected item"); |
@@ -203,29 +206,6 @@ fn extern_block(p: &mut Parser) { | |||
203 | p.expect(R_CURLY); | 206 | p.expect(R_CURLY); |
204 | } | 207 | } |
205 | 208 | ||
206 | fn mod_item(p: &mut Parser) { | ||
207 | assert!(p.at(MOD_KW)); | ||
208 | p.bump(); | ||
209 | |||
210 | if p.expect(IDENT) && !p.eat(SEMI) { | ||
211 | if p.expect(L_CURLY) { | ||
212 | mod_contents(p, true); | ||
213 | p.expect(R_CURLY); | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | |||
218 | fn abi(p: &mut Parser) { | ||
219 | assert!(p.at(EXTERN_KW)); | ||
220 | let abi = p.start(); | ||
221 | p.bump(); | ||
222 | match p.current() { | ||
223 | STRING | RAW_STRING => p.bump(), | ||
224 | _ => (), | ||
225 | } | ||
226 | abi.complete(p, ABI); | ||
227 | } | ||
228 | |||
229 | fn fn_item(p: &mut Parser) { | 209 | fn fn_item(p: &mut Parser) { |
230 | assert!(p.at(FN_KW)); | 210 | assert!(p.at(FN_KW)); |
231 | p.bump(); | 211 | p.bump(); |
@@ -248,3 +228,47 @@ fn fn_item(p: &mut Parser) { | |||
248 | p.expect(R_PAREN); | 228 | p.expect(R_PAREN); |
249 | } | 229 | } |
250 | } | 230 | } |
231 | |||
232 | // test type_item | ||
233 | // type Foo = Bar; | ||
234 | fn type_item(p: &mut Parser) { | ||
235 | assert!(p.at(TYPE_KW)); | ||
236 | p.bump(); | ||
237 | |||
238 | p.expect(IDENT); | ||
239 | |||
240 | // test type_item_type_params | ||
241 | // type Result<T> = (); | ||
242 | type_params::list(p); | ||
243 | |||
244 | // test type_item_where_clause | ||
245 | // type Foo where Foo: Copy = (); | ||
246 | type_params::where_clause(p); | ||
247 | |||
248 | p.expect(EQ); | ||
249 | types::type_ref(p); | ||
250 | p.expect(SEMI); | ||
251 | } | ||
252 | |||
253 | fn mod_item(p: &mut Parser) { | ||
254 | assert!(p.at(MOD_KW)); | ||
255 | p.bump(); | ||
256 | |||
257 | if p.expect(IDENT) && !p.eat(SEMI) { | ||
258 | if p.expect(L_CURLY) { | ||
259 | mod_contents(p, true); | ||
260 | p.expect(R_CURLY); | ||
261 | } | ||
262 | } | ||
263 | } | ||
264 | |||
265 | fn abi(p: &mut Parser) { | ||
266 | assert!(p.at(EXTERN_KW)); | ||
267 | let abi = p.start(); | ||
268 | p.bump(); | ||
269 | match p.current() { | ||
270 | STRING | RAW_STRING => p.bump(), | ||
271 | _ => (), | ||
272 | } | ||
273 | abi.complete(p, ABI); | ||
274 | } | ||
diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index 12c9a5362..8f62a471c 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs | |||
@@ -70,6 +70,11 @@ pub(super) fn list(p: &mut Parser) { | |||
70 | 70 | ||
71 | pub(super) fn where_clause(p: &mut Parser) { | 71 | pub(super) fn where_clause(p: &mut Parser) { |
72 | if p.at(WHERE_KW) { | 72 | if p.at(WHERE_KW) { |
73 | let m = p.start(); | ||
73 | p.bump(); | 74 | p.bump(); |
75 | p.expect(IDENT); | ||
76 | p.expect(COLON); | ||
77 | p.expect(IDENT); | ||
78 | m.complete(p, WHERE_CLAUSE); | ||
74 | } | 79 | } |
75 | } | 80 | } |
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 1a3d44a0a..c798edd08 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs | |||
@@ -1,5 +1,14 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn type_ref(p: &mut Parser) { | 3 | pub(super) fn type_ref(p: &mut Parser) { |
4 | p.expect(IDENT); | 4 | match p.current() { |
5 | IDENT => p.bump(), | ||
6 | L_PAREN => { | ||
7 | p.bump(); | ||
8 | p.expect(R_PAREN); | ||
9 | } | ||
10 | _ => { | ||
11 | p.error("expected type"); | ||
12 | } | ||
13 | } | ||
5 | } | 14 | } |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 27bc1cafa..dc287f0f4 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -83,6 +83,7 @@ pub enum SyntaxKind { | |||
83 | STATIC_KW, | 83 | STATIC_KW, |
84 | MUT_KW, | 84 | MUT_KW, |
85 | UNSAFE_KW, | 85 | UNSAFE_KW, |
86 | TYPE_KW, | ||
86 | AUTO_KW, | 87 | AUTO_KW, |
87 | DEFAULT_KW, | 88 | DEFAULT_KW, |
88 | UNION_KW, | 89 | UNION_KW, |
@@ -97,6 +98,7 @@ pub enum SyntaxKind { | |||
97 | CONST_ITEM, | 98 | CONST_ITEM, |
98 | TRAIT_ITEM, | 99 | TRAIT_ITEM, |
99 | IMPL_ITEM, | 100 | IMPL_ITEM, |
101 | TYPE_ITEM, | ||
100 | EXTERN_BLOCK, | 102 | EXTERN_BLOCK, |
101 | ENUM_VARIANT, | 103 | ENUM_VARIANT, |
102 | NAMED_FIELD, | 104 | NAMED_FIELD, |
@@ -110,6 +112,7 @@ pub enum SyntaxKind { | |||
110 | ALIAS, | 112 | ALIAS, |
111 | VISIBILITY, | 113 | VISIBILITY, |
112 | TYPE_PARAM_LIST, | 114 | TYPE_PARAM_LIST, |
115 | WHERE_CLAUSE, | ||
113 | LIFETIME_PARAM, | 116 | LIFETIME_PARAM, |
114 | TYPE_PARAM, | 117 | TYPE_PARAM, |
115 | ABI, | 118 | ABI, |
@@ -203,6 +206,7 @@ impl SyntaxKind { | |||
203 | STATIC_KW => &SyntaxInfo { name: "STATIC_KW" }, | 206 | STATIC_KW => &SyntaxInfo { name: "STATIC_KW" }, |
204 | MUT_KW => &SyntaxInfo { name: "MUT_KW" }, | 207 | MUT_KW => &SyntaxInfo { name: "MUT_KW" }, |
205 | UNSAFE_KW => &SyntaxInfo { name: "UNSAFE_KW" }, | 208 | UNSAFE_KW => &SyntaxInfo { name: "UNSAFE_KW" }, |
209 | TYPE_KW => &SyntaxInfo { name: "TYPE_KW" }, | ||
206 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, | 210 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, |
207 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, | 211 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, |
208 | UNION_KW => &SyntaxInfo { name: "UNION_KW" }, | 212 | UNION_KW => &SyntaxInfo { name: "UNION_KW" }, |
@@ -217,6 +221,7 @@ impl SyntaxKind { | |||
217 | CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" }, | 221 | CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" }, |
218 | TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, | 222 | TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, |
219 | IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, | 223 | IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, |
224 | TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" }, | ||
220 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 225 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
221 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 226 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
222 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 227 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
@@ -230,6 +235,7 @@ impl SyntaxKind { | |||
230 | ALIAS => &SyntaxInfo { name: "ALIAS" }, | 235 | ALIAS => &SyntaxInfo { name: "ALIAS" }, |
231 | VISIBILITY => &SyntaxInfo { name: "VISIBILITY" }, | 236 | VISIBILITY => &SyntaxInfo { name: "VISIBILITY" }, |
232 | TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, | 237 | TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, |
238 | WHERE_CLAUSE => &SyntaxInfo { name: "WHERE_CLAUSE" }, | ||
233 | LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, | 239 | LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, |
234 | TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, | 240 | TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, |
235 | ABI => &SyntaxInfo { name: "ABI" }, | 241 | ABI => &SyntaxInfo { name: "ABI" }, |
@@ -268,6 +274,7 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> { | |||
268 | "static" => Some(STATIC_KW), | 274 | "static" => Some(STATIC_KW), |
269 | "mut" => Some(MUT_KW), | 275 | "mut" => Some(MUT_KW), |
270 | "unsafe" => Some(UNSAFE_KW), | 276 | "unsafe" => Some(UNSAFE_KW), |
277 | "type" => Some(TYPE_KW), | ||
271 | _ => None, | 278 | _ => None, |
272 | } | 279 | } |
273 | } | 280 | } |