diff options
author | Aleksey Kladov <[email protected]> | 2018-02-11 08:37:08 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-02-11 08:37:08 +0000 |
commit | 555c4ae37560493fd901aad41951ad1664043459 (patch) | |
tree | 89a260412886182f2a4f571694cfbff734f1dc3d /src/parser/grammar/types.rs | |
parent | ceb94ece2aa6a1b54063c582663fff4c1937d989 (diff) |
G: slice & array types
Diffstat (limited to 'src/parser/grammar/types.rs')
-rw-r--r-- | src/parser/grammar/types.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index ceadf5f96..4eb333b54 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs | |||
@@ -5,6 +5,7 @@ pub(super) fn type_(p: &mut Parser) { | |||
5 | L_PAREN => paren_or_tuple_type(p), | 5 | L_PAREN => paren_or_tuple_type(p), |
6 | EXCL => never_type(p), | 6 | EXCL => never_type(p), |
7 | STAR => pointer_type(p), | 7 | STAR => pointer_type(p), |
8 | L_BRACK => array_or_slice_type(p), | ||
8 | IDENT => path_type(p), | 9 | IDENT => path_type(p), |
9 | _ => { | 10 | _ => { |
10 | p.error("expected type"); | 11 | p.error("expected type"); |
@@ -82,6 +83,38 @@ fn pointer_type(p: &mut Parser) { | |||
82 | m.complete(p, POINTER_TYPE); | 83 | m.complete(p, POINTER_TYPE); |
83 | } | 84 | } |
84 | 85 | ||
86 | fn array_or_slice_type(p: &mut Parser) { | ||
87 | assert!(p.at(L_BRACK)); | ||
88 | let m = p.start(); | ||
89 | p.bump(); | ||
90 | |||
91 | type_(p); | ||
92 | let kind = match p.current() { | ||
93 | // test slice_type | ||
94 | // type T = [()]; | ||
95 | R_BRACK => { | ||
96 | p.bump(); | ||
97 | SLICE_TYPE | ||
98 | }, | ||
99 | |||
100 | // test array_type | ||
101 | // type T = [(); 92]; | ||
102 | SEMI => { | ||
103 | p.bump(); | ||
104 | expressions::expr(p); | ||
105 | p.expect(R_BRACK); | ||
106 | ARRAY_TYPE | ||
107 | } | ||
108 | // test array_type_missing_semi | ||
109 | // type T = [() 92]; | ||
110 | _ => { | ||
111 | p.error("expected `;` or `]`"); | ||
112 | SLICE_TYPE | ||
113 | } | ||
114 | }; | ||
115 | m.complete(p, kind); | ||
116 | } | ||
117 | |||
85 | fn path_type(p: &mut Parser) { | 118 | fn path_type(p: &mut Parser) { |
86 | assert!(p.at(IDENT)); | 119 | assert!(p.at(IDENT)); |
87 | let m = p.start(); | 120 | let m = p.start(); |