diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index ccd3f8e7627..fed5cca512d 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs @@ -69,12 +69,20 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) { // 302 .. => (), // } // } + + // FIXME: support half_open_range_patterns (`..=2`), + // exclusive_range_pattern (`..5`) with missing lhs for &range_op in [T![...], T![..=], T![..]].iter() { if p.at(range_op) { let m = lhs.precede(p); p.bump(range_op); - if !p.at(T![=>]) { - // not a range pat like `302 .. => ()` + + // `0 .. =>` or `let 0 .. =` + // ^ ^ + if p.at(T![=]) { + // test half_open_range_pat + // fn f() { let 0 .. = 1u32; } + } else { atom_pat(p, recovery_set); } m.complete(p, RANGE_PAT); diff --git a/crates/syntax/test_data/parser/inline/ok/0166_half_open_range_pat.rast b/crates/syntax/test_data/parser/inline/ok/0166_half_open_range_pat.rast new file mode 100644 index 00000000000..67ac6a4633f --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0166_half_open_range_pat.rast @@ -0,0 +1,31 @@ +SOURCE_FILE@0..28 + FN@0..27 + FN_KW@0..2 "fn" + WHITESPACE@2..3 " " + NAME@3..4 + IDENT@3..4 "f" + PARAM_LIST@4..6 + L_PAREN@4..5 "(" + R_PAREN@5..6 ")" + WHITESPACE@6..7 " " + BLOCK_EXPR@7..27 + L_CURLY@7..8 "{" + WHITESPACE@8..9 " " + LET_STMT@9..25 + LET_KW@9..12 "let" + WHITESPACE@12..13 " " + RANGE_PAT@13..17 + LITERAL_PAT@13..14 + LITERAL@13..14 + INT_NUMBER@13..14 "0" + WHITESPACE@14..15 " " + DOT2@15..17 ".." + WHITESPACE@17..18 " " + EQ@18..19 "=" + WHITESPACE@19..20 " " + LITERAL@20..24 + INT_NUMBER@20..24 "1u32" + SEMICOLON@24..25 ";" + WHITESPACE@25..26 " " + R_CURLY@26..27 "}" + WHITESPACE@27..28 "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0166_half_open_range_pat.rs b/crates/syntax/test_data/parser/inline/ok/0166_half_open_range_pat.rs new file mode 100644 index 00000000000..1360eda0565 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0166_half_open_range_pat.rs @@ -0,0 +1 @@ +fn f() { let 0 .. = 1u32; }