fix: parse the range pat inside the tuple pat

This commit is contained in:
zhoufan 2021-11-18 11:11:37 +08:00
parent fdd49b9713
commit a539b5e693
3 changed files with 168 additions and 82 deletions

View file

@ -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 {

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..223
FN@0..222
SOURCE_FILE@0..307
FN@0..306
FN_KW@0..2 "fn"
WHITESPACE@2..3 " "
NAME@3..7
@ -8,8 +8,8 @@ SOURCE_FILE@0..223
L_PAREN@7..8 "("
R_PAREN@8..9 ")"
WHITESPACE@9..10 " "
BLOCK_EXPR@10..222
STMT_LIST@10..222
BLOCK_EXPR@10..306
STMT_LIST@10..306
L_CURLY@10..11 "{"
WHITESPACE@11..16 "\n "
EXPR_STMT@16..132
@ -96,6 +96,7 @@ SOURCE_FILE@0..223
WHITESPACE@126..131 "\n "
R_CURLY@131..132 "}"
WHITESPACE@132..138 "\n\n "
EXPR_STMT@138..220
MATCH_EXPR@138..220
MATCH_KW@138..143 "match"
WHITESPACE@143..144 " "
@ -170,6 +171,81 @@ SOURCE_FILE@0..223
R_PAREN@213..214 ")"
WHITESPACE@214..219 "\n "
R_CURLY@219..220 "}"
WHITESPACE@220..221 "\n"
R_CURLY@221..222 "}"
WHITESPACE@222..223 "\n"
WHITESPACE@220..226 "\n\n "
MATCH_EXPR@226..304
MATCH_KW@226..231 "match"
WHITESPACE@231..232 " "
TUPLE_EXPR@232..251
L_PAREN@232..233 "("
CAST_EXPR@233..241
LITERAL@233..235
INT_NUMBER@233..235 "10"
WHITESPACE@235..236 " "
AS_KW@236..238 "as"
WHITESPACE@238..239 " "
PATH_TYPE@239..241
PATH@239..241
PATH_SEGMENT@239..241
NAME_REF@239..241
IDENT@239..241 "u8"
COMMA@241..242 ","
WHITESPACE@242..243 " "
CAST_EXPR@243..250
LITERAL@243..244
INT_NUMBER@243..244 "5"
WHITESPACE@244..245 " "
AS_KW@245..247 "as"
WHITESPACE@247..248 " "
PATH_TYPE@248..250
PATH@248..250
PATH_SEGMENT@248..250
NAME_REF@248..250
IDENT@248..250 "u8"
R_PAREN@250..251 ")"
WHITESPACE@251..252 " "
MATCH_ARM_LIST@252..304
L_CURLY@252..253 "{"
WHITESPACE@253..262 "\n "
MATCH_ARM@262..275
TUPLE_PAT@262..268
L_PAREN@262..263 "("
LITERAL_PAT@263..264
LITERAL@263..264
INT_NUMBER@263..264 "0"
COMMA@264..265 ","
WHITESPACE@265..266 " "
WILDCARD_PAT@266..267
UNDERSCORE@266..267 "_"
R_PAREN@267..268 ")"
WHITESPACE@268..269 " "
FAT_ARROW@269..271 "=>"
WHITESPACE@271..272 " "
TUPLE_EXPR@272..274
L_PAREN@272..273 "("
R_PAREN@273..274 ")"
COMMA@274..275 ","
WHITESPACE@275..284 "\n "
MATCH_ARM@284..298
TUPLE_PAT@284..292
L_PAREN@284..285 "("
RANGE_PAT@285..288
LITERAL_PAT@285..286
LITERAL@285..286
INT_NUMBER@285..286 "1"
DOT2@286..288 ".."
COMMA@288..289 ","
WHITESPACE@289..290 " "
WILDCARD_PAT@290..291
UNDERSCORE@290..291 "_"
R_PAREN@291..292 ")"
WHITESPACE@292..293 " "
FAT_ARROW@293..295 "=>"
WHITESPACE@295..296 " "
TUPLE_EXPR@296..298
L_PAREN@296..297 "("
R_PAREN@297..298 ")"
WHITESPACE@298..303 "\n "
R_CURLY@303..304 "}"
WHITESPACE@304..305 "\n"
R_CURLY@305..306 "}"
WHITESPACE@306..307 "\n"

View file

@ -10,4 +10,9 @@ fn main() {
Some(0) | None => (),
Some(1..) => ()
}
match (10 as u8, 5 as u8) {
(0, _) => (),
(1.., _) => ()
}
}