Unnamed repository; edit this file 'description' to name the repository.
fix: parse the range pat inside the tuple pat
zhoufan 2021-11-18
parent fdd49b9 · commit a539b5e
-rw-r--r--crates/parser/src/grammar/patterns.rs7
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0058_range_pat.rast238
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0058_range_pat.rs5
3 files changed, 168 insertions, 82 deletions
diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs
index 9da94ce162..70ff87b238 100644
--- a/crates/parser/src/grammar/patterns.rs
+++ b/crates/parser/src/grammar/patterns.rs
@@ -74,6 +74,11 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
// Some(0) | None => (),
// Some(1..) => ()
// }
+ //
+ // match (10 as u8, 5 as u8) {
+ // (0, _) => (),
+ // (1.., _) => ()
+ // }
// }
// FIXME: support half_open_range_patterns (`..=2`),
@@ -85,7 +90,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
// `0 .. =>` or `let 0 .. =` or `Some(0 .. )`
// ^ ^ ^
- if p.at(T![=]) | p.at(T![')']) {
+ if p.at(T![=]) | p.at(T![')']) | p.at(T![,]) {
// test half_open_range_pat
// fn f() { let 0 .. = 1u32; }
} else {
diff --git a/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rast b/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rast
index 5d5803f751..0eb5af54b8 100644
--- a/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rast
+++ b/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rast
@@ -1,5 +1,5 @@
@@ -8,8 +8,8 @@ [email protected]
@@ -96,80 +96,156 @@ [email protected]
diff --git a/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rs b/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rs
index fa91efd212..6c586a8956 100644
--- a/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rs
+++ b/crates/syntax/test_data/parser/inline/ok/0058_range_pat.rs
@@ -10,4 +10,9 @@ fn main() {
Some(0) | None => (),
Some(1..) => ()
}
+
+ match (10 as u8, 5 as u8) {
+ (0, _) => (),
+ (1.., _) => ()
+ }
}