aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar/patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/grammar/patterns.rs')
-rw-r--r--crates/libsyntax2/src/grammar/patterns.rs37
1 files changed, 16 insertions, 21 deletions
diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs
index 29a55cb46..420bae7a7 100644
--- a/crates/libsyntax2/src/grammar/patterns.rs
+++ b/crates/libsyntax2/src/grammar/patterns.rs
@@ -102,21 +102,7 @@ fn path_pat(p: &mut Parser) -> CompletedMarker {
102fn tuple_pat_fields(p: &mut Parser) { 102fn tuple_pat_fields(p: &mut Parser) {
103 assert!(p.at(L_PAREN)); 103 assert!(p.at(L_PAREN));
104 p.bump(); 104 p.bump();
105 while !p.at(EOF) && !p.at(R_PAREN) { 105 pat_list(p, R_PAREN);
106 match p.current() {
107 DOTDOT => p.bump(),
108 _ => {
109 if !p.at_ts(PATTERN_FIRST) {
110 p.error("expected a pattern");
111 break;
112 }
113 pattern(p)
114 }
115 }
116 if !p.at(R_PAREN) {
117 p.expect(COMMA);
118 }
119 }
120 p.expect(R_PAREN); 106 p.expect(R_PAREN);
121} 107}
122 108
@@ -194,18 +180,27 @@ fn slice_pat(p: &mut Parser) -> CompletedMarker {
194 assert!(p.at(L_BRACK)); 180 assert!(p.at(L_BRACK));
195 let m = p.start(); 181 let m = p.start();
196 p.bump(); 182 p.bump();
197 while !p.at(EOF) && !p.at(R_BRACK) { 183 pat_list(p, R_BRACK);
184 p.expect(R_BRACK);
185 m.complete(p, SLICE_PAT)
186}
187
188fn pat_list(p: &mut Parser, ket: SyntaxKind) {
189 while !p.at(EOF) && !p.at(ket) {
198 match p.current() { 190 match p.current() {
199 DOTDOT => p.bump(), 191 DOTDOT => p.bump(),
200 _ => pattern(p), 192 _ => {
193 if !p.at_ts(PATTERN_FIRST) {
194 p.error("expected a pattern");
195 break;
196 }
197 pattern(p)
198 },
201 } 199 }
202 if !p.at(R_BRACK) { 200 if !p.at(ket) {
203 p.expect(COMMA); 201 p.expect(COMMA);
204 } 202 }
205 } 203 }
206 p.expect(R_BRACK);
207
208 m.complete(p, SLICE_PAT)
209} 204}
210 205
211// test bind_pat 206// test bind_pat