Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/parser/src/grammar/patterns.rs')
| -rw-r--r-- | crates/parser/src/grammar/patterns.rs | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index 5fe1a7b13b..9da94ce162 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs @@ -205,46 +205,64 @@ fn tuple_pat_fields(p: &mut Parser) { p.expect(T![')']); } +// test record_pat_field +// fn foo() { +// let S { 0: 1 } = (); +// let S { x: 1 } = (); +// let S { #[cfg(any())] x: 1 } = (); +// } +fn record_pat_field(p: &mut Parser) { + match p.current() { + IDENT | INT_NUMBER if p.nth(1) == T![:] => { + name_ref_or_index(p); + p.bump(T![:]); + pattern(p); + } + T![.] => { + if p.at(T![..]) { + p.bump(T![..]); + } else { + ident_pat(p, false); + } + } + T![box] => { + // FIXME: not all box patterns should be allowed + box_pat(p); + } + _ => { + ident_pat(p, false); + } + } +} + // test record_pat_field_list // fn foo() { // let S {} = (); // let S { f, ref mut g } = (); // let S { h: _, ..} = (); // let S { h: _, } = (); +// let S { #[cfg(any())] .. } = (); // } fn record_pat_field_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); while !p.at(EOF) && !p.at(T!['}']) { + let m = p.start(); + attributes::outer_attrs(p); + match p.current() { // A trailing `..` is *not* treated as a REST_PAT. - T![.] if p.at(T![..]) => p.bump(T![..]), - T!['{'] => error_block(p, "expected ident"), - + T![.] if p.at(T![..]) => { + p.bump(T![..]); + m.complete(p, REST_PAT); + } + T!['{'] => { + error_block(p, "expected ident"); + m.abandon(p); + } _ => { - let m = p.start(); - attributes::outer_attrs(p); - match p.current() { - // test record_pat_field - // fn foo() { - // let S { 0: 1 } = (); - // let S { x: 1 } = (); - // let S { #[cfg(any())] 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); - } - _ => { - ident_pat(p, false); - } - } + record_pat_field(p); m.complete(p, RECORD_PAT_FIELD); } } |