diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-04 08:02:19 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-04 08:02:19 +0100 |
commit | 7a025ad20169253d70bfae3773225404ec7aca46 (patch) | |
tree | f4098b5b74e277867bf54c3404ccfda6fd3493d3 /crates/ra_syntax/src/grammar | |
parent | c87fcb4ea5874a7307c1d9d1192e923f3ae2c922 (diff) | |
parent | a55ef9b3ed66a057bb3e58ab698f26e58afb5b7d (diff) |
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`](https://github.com/rust-lang/rust/blob/441519536c8bd138e8c651743249acd6814747a1/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](https://github.com/matklad/rust-analyzer/blob/c87fcb4ea5874a7307c1d9d1192e923f3ae2c922/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 <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/grammar')
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions/atom.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index f01df56bc..a720d255f 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs | |||
@@ -319,10 +319,13 @@ pub(crate) fn match_arm_list(p: &mut Parser) { | |||
319 | // match () { | 319 | // match () { |
320 | // _ => (), | 320 | // _ => (), |
321 | // X | Y if Z => (), | 321 | // X | Y if Z => (), |
322 | // | X | Y if Z => (), | ||
323 | // | X => (), | ||
322 | // }; | 324 | // }; |
323 | // } | 325 | // } |
324 | fn match_arm(p: &mut Parser) -> BlockLike { | 326 | fn match_arm(p: &mut Parser) -> BlockLike { |
325 | let m = p.start(); | 327 | let m = p.start(); |
328 | p.eat(PIPE); | ||
326 | patterns::pattern_r(p, TokenSet::EMPTY); | 329 | patterns::pattern_r(p, TokenSet::EMPTY); |
327 | while p.eat(PIPE) { | 330 | while p.eat(PIPE) { |
328 | patterns::pattern(p); | 331 | patterns::pattern(p); |