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 | |
parent | ceb94ece2aa6a1b54063c582663fff4c1937d989 (diff) |
G: slice & array types
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/grammar/types.rs | 33 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 4 |
2 files changed, 37 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(); |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 181dcc63b..54200f2d1 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -104,6 +104,8 @@ pub enum SyntaxKind { | |||
104 | NEVER_TYPE, | 104 | NEVER_TYPE, |
105 | PATH_TYPE, | 105 | PATH_TYPE, |
106 | POINTER_TYPE, | 106 | POINTER_TYPE, |
107 | ARRAY_TYPE, | ||
108 | SLICE_TYPE, | ||
107 | EXTERN_BLOCK, | 109 | EXTERN_BLOCK, |
108 | ENUM_VARIANT, | 110 | ENUM_VARIANT, |
109 | NAMED_FIELD, | 111 | NAMED_FIELD, |
@@ -234,6 +236,8 @@ impl SyntaxKind { | |||
234 | NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, | 236 | NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, |
235 | PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, | 237 | PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, |
236 | POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, | 238 | POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, |
239 | ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" }, | ||
240 | SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" }, | ||
237 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 241 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
238 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 242 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
239 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 243 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |