Skip to content
Permalink
Browse files

parser: Remove `look_ahead_span`

  • Loading branch information...
petrochenkov committed Jun 7, 2019
1 parent 6eae6b0 commit 3dbee57daee312ee073006101053f5e3934de7c6
Showing with 5 additions and 18 deletions.
  1. +4 −5 src/libsyntax/parse/literal.rs
  2. +1 −13 src/libsyntax/parse/parser.rs
@@ -271,14 +271,13 @@ impl<'a> Parser<'a> {
let mut recovered = None;
if self.token == token::Dot {
// Attempt to recover `.4` as `0.4`.
recovered = self.look_ahead(1, |t| {
recovered = self.look_ahead(1, |next_token| {
if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix })
= t.kind {
let next_span = self.look_ahead_span(1);
if self.token.span.hi() == next_span.lo() {
= next_token.kind {
if self.token.span.hi() == next_token.span.lo() {
let s = String::from("0.") + &symbol.as_str();
let kind = TokenKind::lit(token::Float, Symbol::intern(&s), suffix);
return Some(Token::new(kind, self.token.span.to(next_span)));
return Some(Token::new(kind, self.token.span.to(next_token.span)));
}
}
None
@@ -1064,18 +1064,6 @@ impl<'a> Parser<'a> {
})
}

crate fn look_ahead_span(&self, dist: usize) -> Span {
if dist == 0 {
return self.token.span
}

match self.token_cursor.frame.tree_cursor.look_ahead(dist - 1) {
Some(TokenTree::Token(token)) => token.span,
Some(TokenTree::Delimited(span, ..)) => span.entire(),
None => self.look_ahead_span(dist - 1),
}
}

/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.
fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool {
self.look_ahead(dist, |t| kws.iter().any(|&kw| t.is_keyword(kw)))
@@ -3067,7 +3055,7 @@ impl<'a> Parser<'a> {
let mut err =
self.sess.span_diagnostic.struct_span_err(self.token.span, &msg);
let span_after_type = parser_snapshot_after_type.token.span;
err.span_label(self.look_ahead_span(1).to(span_after_type),
err.span_label(self.look_ahead(1, |t| t.span).to(span_after_type),
"interpreted as generic arguments");
err.span_label(self.token.span, format!("not interpreted as {}", op_noun));

0 comments on commit 3dbee57

Please sign in to comment.
You can’t perform that action at this time.