mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-04 17:40:50 +00:00
Change parsing of struct field patterns
This commit is contained in:
parent
bcbfa2cc11
commit
fa43ef30f4
5 changed files with 46 additions and 40 deletions
|
@ -910,7 +910,11 @@ impl AstNode for FieldPatList {
|
|||
|
||||
|
||||
impl FieldPatList {
|
||||
pub fn pats(&self) -> impl Iterator<Item = &FieldPat> {
|
||||
pub fn field_pats(&self) -> impl Iterator<Item = &FieldPat> {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn bind_pats(&self) -> impl Iterator<Item = &BindPat> {
|
||||
super::children(self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue