summaryrefslogtreecommitdiffstats
path: root/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs87
1 files changed, 54 insertions, 33 deletions
diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs
index bc1224af9..abcefffa2 100644
--- a/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs
+++ b/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs
@@ -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, _) => (),
+ // }
+ // }
+
+ if p.at(T![..=]) {
+ let m = p.start();
+ p.bump(T![..=]);
+ atom_pat(p, recovery_set);
+ m.complete(p, RANGE_PAT);
+ return;
+ }
- // FIXME: support half_open_range_patterns (`..=2`),
- // exclusive_range_pattern (`..5`) with missing lhs
+ 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);
@@ -115,11 +126,21 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
// ^
// `[0..]`
// ^
- if matches!(p.current(), T![=] | T![,] | T![:] | T![')'] | T!['}'] | T![']']) {
+ // `0 .. if`
+ // ^
+ if matches!(
+ p.current(),
+ T![=] | T![,] | T![:] | T![')'] | T!['}'] | T![']'] | T![if]
+ ) {
// test half_open_range_pat
// fn f() {
// let 0 .. = 1u32;
// let 0..: _ = 1u32;
+ //
+ // match 42 {
+ // 0 .. if true => (),
+ // _ => (),
+ // }
// }
} else {
atom_pat(p, recovery_set);