Parse ..= X patterns

This commit is contained in:
Jonas Schievink 2022-12-13 17:32:25 +01:00
parent 4596847a88
commit 9e0aaf4cf3
4 changed files with 157 additions and 35 deletions

View file

@ -62,39 +62,50 @@ fn pattern_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
}
fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
if let Some(lhs) = atom_pat(p, recovery_set) {
// test range_pat
// fn main() {
// match 92 {
// 0 ... 100 => (),
// 101 ..= 200 => (),
// 200 .. 301 => (),
// 302 .. => (),
// }
//
// match Some(10 as u8) {
// Some(0) | None => (),
// Some(1..) => ()
// }
//
// match () {
// S { a: 0 } => (),
// S { a: 1.. } => (),
// }
//
// match () {
// [0] => (),
// [1..] => (),
// }
//
// match (10 as u8, 5 as u8) {
// (0, _) => (),
// (1.., _) => ()
// }
// }
// test range_pat
// fn main() {
// match 92 {
// 0 ... 100 => (),
// 101 ..= 200 => (),
// 200 .. 301 => (),
// 302 .. => (),
// ..= 303 => (),
// }
//
// match Some(10 as u8) {
// Some(0) | None => (),
// Some(1..) => (),
// Some(..=2) => (),
// }
//
// match () {
// S { a: 0 } => (),
// S { a: 1.. } => (),
// S { a: ..=2 } => (),
// }
//
// match () {
// [0] => (),
// [1..] => (),
// [..=2] => (),
// }
//
// match (10 as u8, 5 as u8) {
// (0, _) => (),
// (1.., _) => (),
// (..=2, _) => (),
// }
// }
// FIXME: support half_open_range_patterns (`..=2`),
// exclusive_range_pattern (`..5`) with missing lhs
if p.at(T![..=]) {
let m = p.start();
p.bump(T![..=]);
atom_pat(p, recovery_set);
m.complete(p, RANGE_PAT);
return;
}
if let Some(lhs) = atom_pat(p, recovery_set) {
for range_op in [T![...], T![..=], T![..]] {
if p.at(range_op) {
let m = lhs.precede(p);