Change parse_expr_tuple_field_access
.
Pass in the span for the field rather than using `prev_token`. Also rename it `mk_expr_tuple_field_access`, because it doesn't do any actual parsing, it just creates an expression with what it's given. Not much of a clarity win by itself, but unlocks additional subsequent simplifications.
This commit is contained in:
parent
90eeb3d681
commit
9c091160dc
1 changed files with 15 additions and 10 deletions
|
@ -1002,22 +1002,25 @@ impl<'a> Parser<'a> {
|
||||||
match self.token.uninterpolate().kind {
|
match self.token.uninterpolate().kind {
|
||||||
token::Ident(..) => self.parse_dot_suffix(base, lo),
|
token::Ident(..) => self.parse_dot_suffix(base, lo),
|
||||||
token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) => {
|
token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) => {
|
||||||
|
let ident_span = self.token.span;
|
||||||
self.bump();
|
self.bump();
|
||||||
Ok(self.parse_expr_tuple_field_access(lo, base, symbol, suffix))
|
Ok(self.mk_expr_tuple_field_access(lo, ident_span, base, symbol, suffix))
|
||||||
}
|
}
|
||||||
token::Literal(token::Lit { kind: token::Float, symbol, suffix }) => {
|
token::Literal(token::Lit { kind: token::Float, symbol, suffix }) => {
|
||||||
Ok(match self.break_up_float(symbol, self.token.span) {
|
Ok(match self.break_up_float(symbol, self.token.span) {
|
||||||
// 1e2
|
// 1e2
|
||||||
DestructuredFloat::Single(sym, _sp) => {
|
DestructuredFloat::Single(sym, _sp) => {
|
||||||
|
let ident_span = self.token.span;
|
||||||
self.bump();
|
self.bump();
|
||||||
self.parse_expr_tuple_field_access(lo, base, sym, suffix)
|
self.mk_expr_tuple_field_access(lo, ident_span, base, sym, suffix)
|
||||||
}
|
}
|
||||||
// 1.
|
// 1.
|
||||||
DestructuredFloat::TrailingDot(sym, ident_span, dot_span) => {
|
DestructuredFloat::TrailingDot(sym, ident_span, dot_span) => {
|
||||||
assert!(suffix.is_none());
|
assert!(suffix.is_none());
|
||||||
self.token = Token::new(token::Ident(sym, IdentIsRaw::No), ident_span);
|
self.token = Token::new(token::Ident(sym, IdentIsRaw::No), ident_span);
|
||||||
|
let ident_span = self.token.span;
|
||||||
self.bump_with((Token::new(token::Dot, dot_span), self.token_spacing));
|
self.bump_with((Token::new(token::Dot, dot_span), self.token_spacing));
|
||||||
self.parse_expr_tuple_field_access(lo, base, sym, None)
|
self.mk_expr_tuple_field_access(lo, ident_span, base, sym, None)
|
||||||
}
|
}
|
||||||
// 1.2 | 1.2e3
|
// 1.2 | 1.2e3
|
||||||
DestructuredFloat::MiddleDot(
|
DestructuredFloat::MiddleDot(
|
||||||
|
@ -1030,13 +1033,16 @@ impl<'a> Parser<'a> {
|
||||||
self.token = Token::new(token::Ident(symbol1, IdentIsRaw::No), ident1_span);
|
self.token = Token::new(token::Ident(symbol1, IdentIsRaw::No), ident1_span);
|
||||||
// This needs to be `Spacing::Alone` to prevent regressions.
|
// This needs to be `Spacing::Alone` to prevent regressions.
|
||||||
// See issue #76399 and PR #76285 for more details
|
// See issue #76399 and PR #76285 for more details
|
||||||
|
let ident_span = self.token.span;
|
||||||
self.bump_with((Token::new(token::Dot, dot_span), Spacing::Alone));
|
self.bump_with((Token::new(token::Dot, dot_span), Spacing::Alone));
|
||||||
let base1 = self.parse_expr_tuple_field_access(lo, base, symbol1, None);
|
let base1 =
|
||||||
|
self.mk_expr_tuple_field_access(lo, ident_span, base, symbol1, None);
|
||||||
let next_token2 =
|
let next_token2 =
|
||||||
Token::new(token::Ident(symbol2, IdentIsRaw::No), ident2_span);
|
Token::new(token::Ident(symbol2, IdentIsRaw::No), ident2_span);
|
||||||
self.bump_with((next_token2, self.token_spacing)); // `.`
|
self.bump_with((next_token2, self.token_spacing)); // `.`
|
||||||
|
let ident_span = self.token.span;
|
||||||
self.bump();
|
self.bump();
|
||||||
self.parse_expr_tuple_field_access(lo, base1, symbol2, suffix)
|
self.mk_expr_tuple_field_access(lo, ident_span, base1, symbol2, suffix)
|
||||||
}
|
}
|
||||||
DestructuredFloat::Error => base,
|
DestructuredFloat::Error => base,
|
||||||
})
|
})
|
||||||
|
@ -1254,19 +1260,18 @@ impl<'a> Parser<'a> {
|
||||||
Ok(fields.into_iter().collect())
|
Ok(fields.into_iter().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_expr_tuple_field_access(
|
fn mk_expr_tuple_field_access(
|
||||||
&mut self,
|
&mut self,
|
||||||
lo: Span,
|
lo: Span,
|
||||||
|
ident_span: Span,
|
||||||
base: P<Expr>,
|
base: P<Expr>,
|
||||||
field: Symbol,
|
field: Symbol,
|
||||||
suffix: Option<Symbol>,
|
suffix: Option<Symbol>,
|
||||||
) -> P<Expr> {
|
) -> P<Expr> {
|
||||||
let span = self.prev_token.span;
|
|
||||||
let field = ExprKind::Field(base, Ident::new(field, span));
|
|
||||||
if let Some(suffix) = suffix {
|
if let Some(suffix) = suffix {
|
||||||
self.expect_no_tuple_index_suffix(span, suffix);
|
self.expect_no_tuple_index_suffix(ident_span, suffix);
|
||||||
}
|
}
|
||||||
self.mk_expr(lo.to(span), field)
|
self.mk_expr(lo.to(ident_span), ExprKind::Field(base, Ident::new(field, ident_span)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a function call expression, `expr(...)`.
|
/// Parse a function call expression, `expr(...)`.
|
||||||
|
|
Loading…
Add table
Reference in a new issue