aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-03-05 09:28:53 +0000
committerVille Penttinen <[email protected]>2019-03-05 09:31:25 +0000
commiteb1ac43867921501723457846f7aaaa36cd4ebdd (patch)
treebd835b7ceb245823d5ddd7bd725c99463e798774
parent1f4468a8dae10db4f500bde3c1708228de6137b6 (diff)
Introduce pattern_list to parse pipe separated patterns
pattern_list comes in two variants, one uses the default PAT_RECOVERY_SET as the recovery set, while other allows the user to provide a recovery set.
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs12
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs16
2 files changed, 18 insertions, 10 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index dfa391632..9f282c74d 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -290,11 +290,7 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
290fn cond(p: &mut Parser) { 290fn cond(p: &mut Parser) {
291 let m = p.start(); 291 let m = p.start();
292 if p.eat(LET_KW) { 292 if p.eat(LET_KW) {
293 p.eat(PIPE); 293 patterns::pattern_list(p);
294 patterns::pattern(p);
295 while p.eat(PIPE) {
296 patterns::pattern(p);
297 }
298 p.expect(EQ); 294 p.expect(EQ);
299 } 295 }
300 expr_no_struct(p); 296 expr_no_struct(p);
@@ -386,11 +382,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
386// } 382// }
387fn match_arm(p: &mut Parser) -> BlockLike { 383fn match_arm(p: &mut Parser) -> BlockLike {
388 let m = p.start(); 384 let m = p.start();
389 p.eat(PIPE); 385 patterns::pattern_list_r(p, TokenSet::empty());
390 patterns::pattern_r(p, TokenSet::empty());
391 while p.eat(PIPE) {
392 patterns::pattern(p);
393 }
394 if p.at(IF_KW) { 386 if p.at(IF_KW) {
395 match_guard(p); 387 match_guard(p);
396 } 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