diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-10 21:47:04 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-10 21:47:04 +0000 |
commit | e19d038a0e1d9af8270450c5fe8fbbdf0f15cb24 (patch) | |
tree | 5bac76244148ce5b368bc8cb83a05cc184c452a7 /src | |
parent | b814d931514cdc250f9156dabd874edf685569d0 (diff) | |
parent | b097090690f5edbe03f4aa9d042ba26c123699e4 (diff) |
Merge #47
47: G: more types r=matklad a=matklad
bors r+
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/grammar/items/consts.rs | 2 | ||||
-rw-r--r-- | src/parser/grammar/items/mod.rs | 2 | ||||
-rw-r--r-- | src/parser/grammar/items/structs.rs | 4 | ||||
-rw-r--r-- | src/parser/grammar/type_params.rs | 2 | ||||
-rw-r--r-- | src/parser/grammar/types.rs | 49 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 8 |
6 files changed, 56 insertions, 11 deletions
diff --git a/src/parser/grammar/items/consts.rs b/src/parser/grammar/items/consts.rs index 8117af706..5f3cf58c2 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::type_ref(p); | 17 | types::ty(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 8bb821fb6..f1776e0e2 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -247,7 +247,7 @@ fn type_item(p: &mut Parser) { | |||
247 | type_params::where_clause(p); | 247 | type_params::where_clause(p); |
248 | 248 | ||
249 | p.expect(EQ); | 249 | p.expect(EQ); |
250 | types::type_ref(p); | 250 | types::ty(p); |
251 | p.expect(SEMI); | 251 | p.expect(SEMI); |
252 | } | 252 | } |
253 | 253 | ||
diff --git a/src/parser/grammar/items/structs.rs b/src/parser/grammar/items/structs.rs index eca0d2e64..ad18fd270 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::type_ref(p); | 92 | types::ty(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::type_ref(p); | 108 | types::ty(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/type_params.rs b/src/parser/grammar/type_params.rs index 8f62a471c..2462b260e 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::type_ref(p) | 65 | types::ty(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 c798edd08..71801d8ef 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs | |||
@@ -1,14 +1,51 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn type_ref(p: &mut Parser) { | 3 | pub(super) fn ty(p: &mut Parser) { |
4 | match p.current() { | 4 | match p.current() { |
5 | IDENT => p.bump(), | 5 | L_PAREN => paren_or_tuple_ty(p), |
6 | L_PAREN => { | 6 | IDENT => path_type(p), |
7 | p.bump(); | ||
8 | p.expect(R_PAREN); | ||
9 | } | ||
10 | _ => { | 7 | _ => { |
11 | p.error("expected type"); | 8 | p.error("expected type"); |
12 | } | 9 | } |
13 | } | 10 | } |
14 | } | 11 | } |
12 | |||
13 | fn paren_or_tuple_ty(p: &mut Parser) { | ||
14 | assert!(p.at(L_PAREN)); | ||
15 | let m = p.start(); | ||
16 | p.bump(); | ||
17 | let mut n_types: u32 = 0; | ||
18 | let mut trailing_comma: bool = false; | ||
19 | while !p.at(EOF) && !p.at(R_PAREN) { | ||
20 | n_types += 1; | ||
21 | ty(p); | ||
22 | if p.eat(COMMA) { | ||
23 | trailing_comma = true; | ||
24 | } else { | ||
25 | trailing_comma = false; | ||
26 | break; | ||
27 | } | ||
28 | } | ||
29 | p.expect(R_PAREN); | ||
30 | |||
31 | let kind = if n_types == 1 && !trailing_comma { | ||
32 | // test paren_type | ||
33 | // type T = (i32); | ||
34 | PAREN_TYPE | ||
35 | } else { | ||
36 | // test unit_type | ||
37 | // type T = (); | ||
38 | |||
39 | // test singleton_tuple_type | ||
40 | // type T = (i32,); | ||
41 | TUPLE_TYPE | ||
42 | }; | ||
43 | m.complete(p, kind); | ||
44 | } | ||
45 | |||
46 | fn path_type(p: &mut Parser) { | ||
47 | assert!(p.at(IDENT)); | ||
48 | let m = p.start(); | ||
49 | paths::type_path(p); | ||
50 | m.complete(p, PATH_TYPE); | ||
51 | } | ||
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 7450f9d6f..630d3d2a5 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -99,6 +99,10 @@ pub enum SyntaxKind { | |||
99 | TRAIT_ITEM, | 99 | TRAIT_ITEM, |
100 | IMPL_ITEM, | 100 | IMPL_ITEM, |
101 | TYPE_ITEM, | 101 | TYPE_ITEM, |
102 | PAREN_TYPE, | ||
103 | TUPLE_TYPE, | ||
104 | NEVER_TYPE, | ||
105 | PATH_TYPE, | ||
102 | EXTERN_BLOCK, | 106 | EXTERN_BLOCK, |
103 | ENUM_VARIANT, | 107 | ENUM_VARIANT, |
104 | NAMED_FIELD, | 108 | NAMED_FIELD, |
@@ -224,6 +228,10 @@ impl SyntaxKind { | |||
224 | TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, | 228 | TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, |
225 | IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, | 229 | IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, |
226 | TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" }, | 230 | TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" }, |
231 | PAREN_TYPE => &SyntaxInfo { name: "PAREN_TYPE" }, | ||
232 | TUPLE_TYPE => &SyntaxInfo { name: "TUPLE_TYPE" }, | ||
233 | NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, | ||
234 | PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, | ||
227 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 235 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
228 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 236 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
229 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 237 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |