diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-07 00:16:19 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-23 13:44:12 +0100 |
| commit | a15d0cde57c339775639e7cb4d6f7535b418b371 (patch) | |
| tree | 8f18175f4996f3b7eca9bee13f5b5bee5af2dcd3 | |
| parent | 287ba5d0c8383c011b248db5b8a7a65b52fdd242 (diff) | |
| download | rust-a15d0cde57c339775639e7cb4d6f7535b418b371.tar.gz rust-a15d0cde57c339775639e7cb4d6f7535b418b371.zip | |
extract parse_tuple_field_access_expr
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index f20e5d6aa92..d1b133d6c63 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -708,12 +708,7 @@ impl<'a> Parser<'a> { e = self.parse_dot_suffix(e, lo)?; } token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) => { - let span = self.token.span; - self.bump(); - let field = ExprKind::Field(e, Ident::new(symbol, span)); - e = self.mk_expr(lo.to(span), field, AttrVec::new()); - - self.expect_no_suffix(span, "a tuple index", suffix); + e = self.parse_tuple_field_access_expr(lo, e, symbol, suffix); } token::Literal(token::Lit { kind: token::Float, symbol, .. }) => { self.bump(); @@ -756,7 +751,7 @@ impl<'a> Parser<'a> { break; } match self.token.kind { - token::OpenDelim(token::Paren) => e = Ok(self.parse_fn_call_expr(lo, e)), + token::OpenDelim(token::Paren) => e = self.parse_fn_call_expr(lo, e), token::OpenDelim(token::Bracket) => e = self.parse_index_expr(lo, e)?, _ => return Ok(e), } @@ -764,6 +759,20 @@ impl<'a> Parser<'a> { return Ok(e); } + fn parse_tuple_field_access_expr( + &mut self, + lo: Span, + base: P<Expr>, + field: Symbol, + suffix: Option<Symbol>, + ) -> P<Expr> { + let span = self.token.span; + self.bump(); + let field = ExprKind::Field(base, Ident::new(field, span)); + self.expect_no_suffix(span, "a tuple index", suffix); + self.mk_expr(lo.to(span), field, AttrVec::new()) + } + /// Parse a function call expression, `expr(...)`. fn parse_fn_call_expr(&mut self, lo: Span, fun: P<Expr>) -> P<Expr> { let seq = self.parse_paren_expr_seq().map(|args| { |
