diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-12 08:27:01 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-12 12:50:44 +0200 |
| commit | e32bd69d0f7443bf76af4a8129fc43b381e5afaa (patch) | |
| tree | ce7967f07c7339a3105d8f8d0743dbcda333879d /src/libsyntax/parse/parser | |
| parent | 231da7e044255286ba92675e89ca168a4932452c (diff) | |
| download | rust-e32bd69d0f7443bf76af4a8129fc43b381e5afaa.tar.gz rust-e32bd69d0f7443bf76af4a8129fc43b381e5afaa.zip | |
extract parse_pat_mac_invoc
Diffstat (limited to 'src/libsyntax/parse/parser')
| -rw-r--r-- | src/libsyntax/parse/parser/pat.rs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs index 7c7dad1fd94..40dfa86834f 100644 --- a/src/libsyntax/parse/parser/pat.rs +++ b/src/libsyntax/parse/parser/pat.rs @@ -3,7 +3,7 @@ use super::{Parser, PResult, PathStyle}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; use crate::ptr::P; use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac_}; -use crate::ast::{BindingMode, Ident, Mutability, Expr, ExprKind}; +use crate::ast::{BindingMode, Ident, Mutability, Path, Expr, ExprKind}; use crate::parse::token::{self}; use crate::print::pprust; use crate::source_map::{respan, Span, Spanned}; @@ -165,18 +165,7 @@ impl<'a> Parser<'a> { (None, self.parse_path(PathStyle::Expr)?) }; match self.token.kind { - token::Not if qself.is_none() => { - // Parse macro invocation - self.bump(); - let (delim, tts) = self.expect_delimited_token_tree()?; - let mac = respan(lo.to(self.prev_span), Mac_ { - path, - tts, - delim, - prior_type_ascription: self.last_type_ascription, - }); - PatKind::Mac(mac) - } + token::Not if qself.is_none() => self.parse_pat_mac_invoc(lo, path)?, token::DotDotDot | token::DotDotEq | token::DotDot => { let (end_kind, form) = match self.token.kind { token::DotDot => (RangeEnd::Excluded, ".."), @@ -328,7 +317,8 @@ impl<'a> Parser<'a> { }) } - // Recover on `mut ref? ident @ pat` and suggest that the order of `mut` and `ref` is incorrect. + /// Recover on `mut ref? ident @ pat` and suggest + /// that the order of `mut` and `ref` is incorrect. fn recover_pat_ident_mut_first(&mut self) -> PResult<'a, PatKind> { let mutref_span = self.prev_span.to(self.token.span); let binding_mode = if self.eat_keyword(kw::Ref) { @@ -347,6 +337,19 @@ impl<'a> Parser<'a> { self.parse_pat_ident(binding_mode) } + /// Parse macro invocation + fn parse_pat_mac_invoc(&mut self, lo: Span, path: Path) -> PResult<'a, PatKind> { + self.bump(); + let (delim, tts) = self.expect_delimited_token_tree()?; + let mac = respan(lo.to(self.prev_span), Mac_ { + path, + tts, + delim, + prior_type_ascription: self.last_type_ascription, + }); + Ok(PatKind::Mac(mac)) + } + // Helper function to decide whether to parse as ident binding // or to try to do something more complex like range patterns. fn parse_as_ident(&mut self) -> bool { |
