aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-05 10:28:24 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-05 10:28:24 +0000
commite7241274ef052fc3081b6dbc2e80266d6703c80c (patch)
tree4428c987a10a08a3cfb1eeaae497a9bc37a6af9a /crates/ra_parser/src
parentfe48f9f4d243aff59abc44e9ef9ccce9d43c01a8 (diff)
parenteb1ac43867921501723457846f7aaaa36cd4ebdd (diff)
Merge #930
930: Add support for parsing multiple if and while-let patterns r=matklad a=vipentti Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs14
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs16
2 files changed, 24 insertions, 6 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index e74305b6a..9f282c74d 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -281,10 +281,16 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
281 281
282// test cond 282// test cond
283// fn foo() { if let Some(_) = None {} } 283// fn foo() { if let Some(_) = None {} }
284// fn bar() {
285// if let Some(_) | Some(_) = None {}
286// if let | Some(_) = None {}
287// while let Some(_) | Some(_) = None {}
288// while let | Some(_) = None {}
289// }
284fn cond(p: &mut Parser) { 290fn cond(p: &mut Parser) {
285 let m = p.start(); 291 let m = p.start();
286 if p.eat(LET_KW) { 292 if p.eat(LET_KW) {
287 patterns::pattern(p); 293 patterns::pattern_list(p);
288 p.expect(EQ); 294 p.expect(EQ);
289 } 295 }
290 expr_no_struct(p); 296 expr_no_struct(p);
@@ -376,11 +382,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
376// } 382// }
377fn match_arm(p: &mut Parser) -> BlockLike { 383fn match_arm(p: &mut Parser) -> BlockLike {
378 let m = p.start(); 384 let m = p.start();
379 p.eat(PIPE); 385 patterns::pattern_list_r(p, TokenSet::empty());
380 patterns::pattern_r(p, TokenSet::empty());
381 while p.eat(PIPE) {
382 patterns::pattern(p);
383 }
384 if p.at(IF_KW) { 386 if p.at(IF_KW) {
385 match_guard(p); 387 match_guard(p);
386 } 388 }
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs
index 9d7da639d..befe6687d 100644
--- a/crates/ra_parser/src/grammar/patterns.rs
+++ b/crates/ra_parser/src/grammar/patterns.rs
@@ -8,6 +8,22 @@ pub(super) fn pattern(p: &mut Parser) {
8 pattern_r(p, PAT_RECOVERY_SET) 8 pattern_r(p, PAT_RECOVERY_SET)
9} 9}
10 10
11/// Parses a pattern list separated by pipes `|`
12pub(super) fn pattern_list(p: &mut Parser) {
13 pattern_list_r(p, PAT_RECOVERY_SET)
14}
15
16/// Parses a pattern list separated by pipes `|`
17/// using the given `recovery_set`
18pub(super) fn pattern_list_r(p: &mut Parser, recovery_set: TokenSet) {
19 p.eat(PIPE);
20 pattern_r(p, recovery_set);
21
22 while p.eat(PIPE) {
23 pattern_r(p, recovery_set);
24 }
25}
26
11pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { 27pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) {
12 if let Some(lhs) = atom_pat(p, recovery_set) { 28 if let Some(lhs) = atom_pat(p, recovery_set) {
13 // test range_pat 29 // test range_pat