From b6f8037a6f8fbcb4f127e1d2b518279650b1f5ea Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Sep 2018 11:26:52 +0300 Subject: don't get stuck in slice patterns --- crates/libsyntax2/src/grammar/patterns.rs | 37 +++++++++++++------------------ 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'crates/libsyntax2/src/grammar') 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 { fn tuple_pat_fields(p: &mut Parser) { assert!(p.at(L_PAREN)); p.bump(); - while !p.at(EOF) && !p.at(R_PAREN) { - match p.current() { - DOTDOT => p.bump(), - _ => { - if !p.at_ts(PATTERN_FIRST) { - p.error("expected a pattern"); - break; - } - pattern(p) - } - } - if !p.at(R_PAREN) { - p.expect(COMMA); - } - } + pat_list(p, R_PAREN); p.expect(R_PAREN); } @@ -194,18 +180,27 @@ fn slice_pat(p: &mut Parser) -> CompletedMarker { assert!(p.at(L_BRACK)); let m = p.start(); p.bump(); - while !p.at(EOF) && !p.at(R_BRACK) { + pat_list(p, R_BRACK); + p.expect(R_BRACK); + m.complete(p, SLICE_PAT) +} + +fn pat_list(p: &mut Parser, ket: SyntaxKind) { + while !p.at(EOF) && !p.at(ket) { match p.current() { DOTDOT => p.bump(), - _ => pattern(p), + _ => { + if !p.at_ts(PATTERN_FIRST) { + p.error("expected a pattern"); + break; + } + pattern(p) + }, } - if !p.at(R_BRACK) { + if !p.at(ket) { p.expect(COMMA); } } - p.expect(R_BRACK); - - m.complete(p, SLICE_PAT) } // test bind_pat -- cgit v1.2.3