diff options
Diffstat (limited to 'src/parser/grammar')
-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 |
5 files changed, 48 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 | } | ||