From fa43ef30f4f96fc8e4ea1f9c4492bcb07b3335ca Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Sat, 19 Jan 2019 01:02:38 +0100 Subject: Change parsing of struct field patterns --- crates/ra_syntax/src/ast/generated.rs | 6 +++++- crates/ra_syntax/src/grammar.ron | 7 ++++++- crates/ra_syntax/src/grammar/patterns.rs | 23 +++++++++++------------ 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 23a573d74..271040bf4 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -910,7 +910,11 @@ impl AstNode for FieldPatList { impl FieldPatList { - pub fn pats(&self) -> impl Iterator { + pub fn field_pats(&self) -> impl Iterator { + super::children(self) + } + + pub fn bind_pats(&self) -> impl Iterator { super::children(self) } } diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index d8c1ae538..fc47c36d3 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -496,7 +496,12 @@ Grammar( "PlaceholderPat": (), "PathPat": ( options: [ "Path" ] ), "StructPat": ( options: ["FieldPatList", "Path"] ), - "FieldPatList": ( collections: [["pats", "FieldPat"]] ), + "FieldPatList": ( + collections: [ + ["field_pats", "FieldPat"], + ["bind_pats", "BindPat"], + ] + ), "FieldPat": ( traits: ["NameOwner"], options: ["Pat"] diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index ff9d94f8a..1ac5efdf6 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs @@ -128,7 +128,11 @@ fn field_pat_list(p: &mut Parser) { while !p.at(EOF) && !p.at(R_CURLY) { match p.current() { DOTDOT => p.bump(), - _ => field_pat(p), + IDENT if p.nth(1) == COLON => field_pat(p), + L_CURLY => error_block(p, "expected ident"), + _ => { + bind_pat(p, false); + } } if !p.at(R_CURLY) { p.expect(COMMA); @@ -139,18 +143,13 @@ fn field_pat_list(p: &mut Parser) { } fn field_pat(p: &mut Parser) { + assert!(p.at(IDENT)); + assert!(p.nth(1) == COLON); + let m = p.start(); - match p.current() { - IDENT if p.nth(1) == COLON => { - name(p); - p.bump(); - pattern(p); - } - L_CURLY => error_block(p, "expected ident"), - _ => { - bind_pat(p, false); - } - } + name(p); + p.bump(); + pattern(p); m.complete(p, FIELD_PAT); } -- cgit v1.2.3