diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-18 22:04:28 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-24 21:53:55 +0200 |
| commit | b7178ef9836fe8e98ffb3f8d4d870c94e6fe816d (patch) | |
| tree | be209608d451a5373e360fd8f6bc550aed058cd9 /src/libsyntax/parse/parser/pat.rs | |
| parent | 8f6a0cdb0fd453580bed74586c6930b1498aa26f (diff) | |
| download | rust-b7178ef9836fe8e98ffb3f8d4d870c94e6fe816d.tar.gz rust-b7178ef9836fe8e98ffb3f8d4d870c94e6fe816d.zip | |
parser: `parse_pats` -> `parse_top_pat{_unpack}`.
Diffstat (limited to 'src/libsyntax/parse/parser/pat.rs')
| -rw-r--r-- | src/libsyntax/parse/parser/pat.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs index 8fab8884ca0..e4a9dc00977 100644 --- a/src/libsyntax/parse/parser/pat.rs +++ b/src/libsyntax/parse/parser/pat.rs @@ -20,19 +20,25 @@ impl<'a> Parser<'a> { self.parse_pat_with_range_pat(true, expected) } - /// Parses patterns, separated by '|' s. - pub(super) fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> { - // Allow a '|' before the pats (RFCs 1925, 2530, and 2535). - self.eat_or_separator(); - - let mut pats = Vec::new(); - loop { - pats.push(self.parse_top_level_pat()?); + // FIXME(or_patterns, Centril | dlrobertson): + // remove this and use `parse_top_pat` everywhere it is used instead. + pub(super) fn parse_top_pat_unpack(&mut self, gate_or: bool) -> PResult<'a, Vec<P<Pat>>> { + self.parse_top_pat(gate_or) + .map(|pat| pat.and_then(|pat| match pat.node { + PatKind::Or(pats) => pats, + node => vec![self.mk_pat(pat.span, node)], + })) + } - if !self.eat_or_separator() { - return Ok(pats); - } + /// Entry point to the main pattern parser. + /// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level. + pub(super) fn parse_top_pat(&mut self, gate_or: bool) -> PResult<'a, P<Pat>> { + // Allow a '|' before the pats (RFCs 1925, 2530, and 2535). + if self.eat_or_separator() && gate_or { + self.sess.gated_spans.or_patterns.borrow_mut().push(self.prev_span); } + + self.parse_pat_with_or(None, gate_or, true) } pub(super) fn parse_top_level_pat(&mut self) -> PResult<'a, P<Pat>> { |
