Parse range patterns in struct and slice without trailing comma

This commit is contained in:
Ryo Yoshida 2022-08-05 20:01:50 +09:00
parent 1c03f45c08
commit a81c7a2974
No known key found for this signature in database
GPG key ID: E25698A930586171
3 changed files with 150 additions and 3 deletions

View file

@ -75,6 +75,16 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
// Some(1..) => ()
// }
//
// match () {
// S { a: 0 } => (),
// S { a: 1.. } => (),
// }
//
// match () {
// [0] => (),
// [1..] => (),
// }
//
// match (10 as u8, 5 as u8) {
// (0, _) => (),
// (1.., _) => ()
@ -88,9 +98,20 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
let m = lhs.precede(p);
p.bump(range_op);
// `0 .. =>` or `let 0 .. =` or `Some(0 .. )`
// ^ ^ ^
if p.at(T![=]) | p.at(T![')']) | p.at(T![,]) {
// testing if we're at one of the following positions:
// `0 .. =>`
// ^
// `let 0 .. =`
// ^
// (1.., _)
// ^
// `Some(0 .. )`
// ^
// `S { t: 0.. }`
// ^
// `[0..]`
// ^
if p.at(T![=]) | p.at(T![')']) | p.at(T![,]) | p.at(T!['}']) | p.at(T![']']) {
// test half_open_range_pat
// fn f() { let 0 .. = 1u32; }
} else {