From 5e5eb6a108b00c573455d8d088742592012707be Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 23:33:17 +0200 Subject: Align grammar for record patterns and literals The grammar now looks like this [name_ref :] pat --- crates/ra_parser/src/grammar/patterns.rs | 50 +++++++++++++++----------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'crates/ra_parser/src/grammar/patterns.rs') diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 936d27575..68fb2fc73 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -192,14 +192,30 @@ fn record_field_pat_list(p: &mut Parser) { match p.current() { // A trailing `..` is *not* treated as a DOT_DOT_PAT. T![.] if p.at(T![..]) => p.bump(T![..]), - - IDENT | INT_NUMBER if p.nth(1) == T![:] => record_field_pat(p), T!['{'] => error_block(p, "expected ident"), - T![box] => { - box_pat(p); - } - _ => { - bind_pat(p, false); + + c => { + let m = p.start(); + match c { + // test record_field_pat + // fn foo() { + // let S { 0: 1 } = (); + // let S { x: 1 } = (); + // } + IDENT | INT_NUMBER if p.nth(1) == T![:] => { + name_ref_or_index(p); + p.bump(T![:]); + pattern(p); + } + T![box] => { + // FIXME: not all box patterns should be allowed + box_pat(p); + } + _ => { + bind_pat(p, false); + } + } + m.complete(p, RECORD_FIELD_PAT); } } if !p.at(T!['}']) { @@ -210,26 +226,6 @@ fn record_field_pat_list(p: &mut Parser) { m.complete(p, RECORD_FIELD_PAT_LIST); } -// test record_field_pat -// fn foo() { -// let S { 0: 1 } = (); -// let S { x: 1 } = (); -// } -fn record_field_pat(p: &mut Parser) { - assert!(p.at(IDENT) || p.at(INT_NUMBER)); - assert!(p.nth(1) == T![:]); - - let m = p.start(); - - if !p.eat(INT_NUMBER) { - name(p) - } - - p.bump_any(); - pattern(p); - m.complete(p, RECORD_FIELD_PAT); -} - // test placeholder_pat // fn main() { let _ = (); } fn placeholder_pat(p: &mut Parser) -> CompletedMarker { -- cgit v1.2.3