diff options
Diffstat (limited to 'src/parser/grammar/types.rs')
-rw-r--r-- | src/parser/grammar/types.rs | 49 |
1 files changed, 43 insertions, 6 deletions
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 | } | ||