diff options
author | Aleksey Kladov <[email protected]> | 2018-08-07 15:00:45 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-07 15:00:45 +0100 |
commit | a04473e2bb95483e84404c57426ee9ed21fa5d6b (patch) | |
tree | df5cb31dc154285516fc9e52ac16a65f45a29a74 /src/grammar/patterns.rs | |
parent | bcd6754f1266ef3f4ce42f76974e379815234494 (diff) |
Semi statements
Diffstat (limited to 'src/grammar/patterns.rs')
-rw-r--r-- | src/grammar/patterns.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/grammar/patterns.rs b/src/grammar/patterns.rs index f1d48b5fa..36ead7561 100644 --- a/src/grammar/patterns.rs +++ b/src/grammar/patterns.rs | |||
@@ -17,6 +17,7 @@ pub(super) fn pattern(p: &mut Parser) { | |||
17 | UNDERSCORE => placeholder_pat(p), | 17 | UNDERSCORE => placeholder_pat(p), |
18 | AMP => ref_pat(p), | 18 | AMP => ref_pat(p), |
19 | L_PAREN => tuple_pat(p), | 19 | L_PAREN => tuple_pat(p), |
20 | L_BRACK => slice_pat(p), | ||
20 | _ => p.err_and_bump("expected pattern"), | 21 | _ => p.err_and_bump("expected pattern"), |
21 | } | 22 | } |
22 | } | 23 | } |
@@ -128,6 +129,28 @@ fn tuple_pat(p: &mut Parser) { | |||
128 | m.complete(p, TUPLE_PAT); | 129 | m.complete(p, TUPLE_PAT); |
129 | } | 130 | } |
130 | 131 | ||
132 | // test slice_pat | ||
133 | // fn main() { | ||
134 | // let [a, b, ..] = []; | ||
135 | // } | ||
136 | fn slice_pat(p: &mut Parser) { | ||
137 | assert!(p.at(L_BRACK)); | ||
138 | let m = p.start(); | ||
139 | p.bump(); | ||
140 | while !p.at(EOF) && !p.at(R_BRACK) { | ||
141 | match p.current() { | ||
142 | DOTDOT => p.bump(), | ||
143 | _ => pattern(p), | ||
144 | } | ||
145 | if !p.at(R_BRACK) { | ||
146 | p.expect(COMMA); | ||
147 | } | ||
148 | } | ||
149 | p.expect(R_BRACK); | ||
150 | |||
151 | m.complete(p, SLICE_PAT); | ||
152 | } | ||
153 | |||
131 | // test bind_pat | 154 | // test bind_pat |
132 | // fn main() { | 155 | // fn main() { |
133 | // let a = (); | 156 | // let a = (); |