mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #93
93: Support leading pipe in match arms r=matklad a=DJMcNab This adds support for match arms of the form: ```rust <...> | X | Y => <...>, | X => <...>, | 1..2 => <...>, etc ``` # Implementation discussion This just naïvely 'eats' a leading pipe if one is available. The equivalent line in the reference `libsyntax` is in [`parse_arm`](441519536c/src/libsyntax/parse/parser.rs (L3552)
). As noted in the comment linked above, this feature was formally introduced as a result of rust-lang/rfcs#1925. This feature is in active use in the [`rust-analyzer` codebase](c87fcb4ea5/crates/ra_syntax/src/syntax_kinds/generated.rs (L231)
) I have added some tests for this feature, but maybe more would be required EDIT: Always looking for feedback - is this PR description over-engineered? Co-authored-by: Daniel McNab <36049421+djmcnab@users.noreply.github.com>
This commit is contained in:
commit
7a025ad201
3 changed files with 59 additions and 12 deletions
|
@ -319,10 +319,13 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
|
||||||
// match () {
|
// match () {
|
||||||
// _ => (),
|
// _ => (),
|
||||||
// X | Y if Z => (),
|
// X | Y if Z => (),
|
||||||
|
// | X | Y if Z => (),
|
||||||
|
// | X => (),
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
fn match_arm(p: &mut Parser) -> BlockLike {
|
fn match_arm(p: &mut Parser) -> BlockLike {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
|
p.eat(PIPE);
|
||||||
patterns::pattern_r(p, TokenSet::EMPTY);
|
patterns::pattern_r(p, TokenSet::EMPTY);
|
||||||
while p.eat(PIPE) {
|
while p.eat(PIPE) {
|
||||||
patterns::pattern(p);
|
patterns::pattern(p);
|
||||||
|
|
|
@ -2,5 +2,7 @@ fn foo() {
|
||||||
match () {
|
match () {
|
||||||
_ => (),
|
_ => (),
|
||||||
X | Y if Z => (),
|
X | Y if Z => (),
|
||||||
|
| X | Y if Z => (),
|
||||||
|
| X => (),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
ROOT@[0; 78)
|
ROOT@[0; 125)
|
||||||
FN_DEF@[0; 77)
|
FN_DEF@[0; 124)
|
||||||
FN_KW@[0; 2)
|
FN_KW@[0; 2)
|
||||||
WHITESPACE@[2; 3)
|
WHITESPACE@[2; 3)
|
||||||
NAME@[3; 6)
|
NAME@[3; 6)
|
||||||
|
@ -8,18 +8,18 @@ ROOT@[0; 78)
|
||||||
L_PAREN@[6; 7)
|
L_PAREN@[6; 7)
|
||||||
R_PAREN@[7; 8)
|
R_PAREN@[7; 8)
|
||||||
WHITESPACE@[8; 9)
|
WHITESPACE@[8; 9)
|
||||||
BLOCK@[9; 77)
|
BLOCK@[9; 124)
|
||||||
L_CURLY@[9; 10)
|
L_CURLY@[9; 10)
|
||||||
WHITESPACE@[10; 15)
|
WHITESPACE@[10; 15)
|
||||||
EXPR_STMT@[15; 75)
|
EXPR_STMT@[15; 122)
|
||||||
MATCH_EXPR@[15; 74)
|
MATCH_EXPR@[15; 121)
|
||||||
MATCH_KW@[15; 20)
|
MATCH_KW@[15; 20)
|
||||||
WHITESPACE@[20; 21)
|
WHITESPACE@[20; 21)
|
||||||
TUPLE_EXPR@[21; 23)
|
TUPLE_EXPR@[21; 23)
|
||||||
L_PAREN@[21; 22)
|
L_PAREN@[21; 22)
|
||||||
R_PAREN@[22; 23)
|
R_PAREN@[22; 23)
|
||||||
WHITESPACE@[23; 24)
|
WHITESPACE@[23; 24)
|
||||||
MATCH_ARM_LIST@[24; 74)
|
MATCH_ARM_LIST@[24; 121)
|
||||||
L_CURLY@[24; 25)
|
L_CURLY@[24; 25)
|
||||||
WHITESPACE@[25; 34)
|
WHITESPACE@[25; 34)
|
||||||
MATCH_ARM@[34; 41)
|
MATCH_ARM@[34; 41)
|
||||||
|
@ -58,9 +58,51 @@ ROOT@[0; 78)
|
||||||
L_PAREN@[65; 66)
|
L_PAREN@[65; 66)
|
||||||
R_PAREN@[66; 67)
|
R_PAREN@[66; 67)
|
||||||
COMMA@[67; 68)
|
COMMA@[67; 68)
|
||||||
WHITESPACE@[68; 73)
|
WHITESPACE@[68; 77)
|
||||||
R_CURLY@[73; 74)
|
MATCH_ARM@[77; 95)
|
||||||
SEMI@[74; 75)
|
PIPE@[77; 78)
|
||||||
WHITESPACE@[75; 76)
|
WHITESPACE@[78; 79)
|
||||||
R_CURLY@[76; 77)
|
BIND_PAT@[79; 80)
|
||||||
WHITESPACE@[77; 78)
|
NAME@[79; 80)
|
||||||
|
IDENT@[79; 80) "X"
|
||||||
|
WHITESPACE@[80; 81)
|
||||||
|
PIPE@[81; 82)
|
||||||
|
WHITESPACE@[82; 83)
|
||||||
|
BIND_PAT@[83; 84)
|
||||||
|
NAME@[83; 84)
|
||||||
|
IDENT@[83; 84) "Y"
|
||||||
|
WHITESPACE@[84; 85)
|
||||||
|
IF_KW@[85; 87)
|
||||||
|
WHITESPACE@[87; 88)
|
||||||
|
PATH_EXPR@[88; 89)
|
||||||
|
PATH@[88; 89)
|
||||||
|
PATH_SEGMENT@[88; 89)
|
||||||
|
NAME_REF@[88; 89)
|
||||||
|
IDENT@[88; 89) "Z"
|
||||||
|
WHITESPACE@[89; 90)
|
||||||
|
FAT_ARROW@[90; 92)
|
||||||
|
WHITESPACE@[92; 93)
|
||||||
|
TUPLE_EXPR@[93; 95)
|
||||||
|
L_PAREN@[93; 94)
|
||||||
|
R_PAREN@[94; 95)
|
||||||
|
COMMA@[95; 96)
|
||||||
|
WHITESPACE@[96; 105)
|
||||||
|
MATCH_ARM@[105; 114)
|
||||||
|
PIPE@[105; 106)
|
||||||
|
WHITESPACE@[106; 107)
|
||||||
|
BIND_PAT@[107; 108)
|
||||||
|
NAME@[107; 108)
|
||||||
|
IDENT@[107; 108) "X"
|
||||||
|
WHITESPACE@[108; 109)
|
||||||
|
FAT_ARROW@[109; 111)
|
||||||
|
WHITESPACE@[111; 112)
|
||||||
|
TUPLE_EXPR@[112; 114)
|
||||||
|
L_PAREN@[112; 113)
|
||||||
|
R_PAREN@[113; 114)
|
||||||
|
COMMA@[114; 115)
|
||||||
|
WHITESPACE@[115; 120)
|
||||||
|
R_CURLY@[120; 121)
|
||||||
|
SEMI@[121; 122)
|
||||||
|
WHITESPACE@[122; 123)
|
||||||
|
R_CURLY@[123; 124)
|
||||||
|
WHITESPACE@[124; 125)
|
||||||
|
|
Loading…
Reference in a new issue