Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the positions of the lexer and parser #36969

Merged
merged 6 commits into from
Oct 18, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename Parser::last_token_kind as prev_token_kind.
Likewise, rename LastTokenKind as PrevTokenKind.

This is a [breaking-change] for libsyntax.
  • Loading branch information
nnethercote committed Oct 4, 2016
commit 3c4c85947cddac2d36854e5bf8c7a8edb32e1245
34 changes: 17 additions & 17 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
}

#[derive(PartialEq)]
enum LastTokenKind {
enum PrevTokenKind {
DocComment,
Comma,
Interpolated,
Expand All @@ -258,7 +258,7 @@ pub struct Parser<'a> {
pub prev_span: Span,
pub cfg: CrateConfig,
/// the previous token kind
last_token_kind: LastTokenKind,
prev_token_kind: PrevTokenKind,
pub buffer: [TokenAndSpan; 4],
pub buffer_start: isize,
pub buffer_end: isize,
Expand Down Expand Up @@ -369,7 +369,7 @@ impl<'a> Parser<'a> {
token: tok0.tok,
span: span,
prev_span: span,
last_token_kind: LastTokenKind::Other,
prev_token_kind: PrevTokenKind::Other,
buffer: [
placeholder.clone(),
placeholder.clone(),
Expand Down Expand Up @@ -504,7 +504,7 @@ impl<'a> Parser<'a> {
expr: PResult<'a, P<Expr>>)
-> PResult<'a, (Span, P<Expr>)> {
expr.map(|e| {
if self.last_token_kind == LastTokenKind::Interpolated {
if self.prev_token_kind == PrevTokenKind::Interpolated {
(self.prev_span, e)
} else {
(e.span, e)
Expand All @@ -524,7 +524,7 @@ impl<'a> Parser<'a> {
self.bug("ident interpolation not converted to real token");
}
_ => {
Err(if self.last_token_kind == LastTokenKind::DocComment {
Err(if self.prev_token_kind == PrevTokenKind::DocComment {
self.span_fatal_help(self.prev_span,
"found a documentation comment that doesn't document anything",
"doc comments must come before what they document, maybe a comment was \
Expand Down Expand Up @@ -922,20 +922,20 @@ impl<'a> Parser<'a> {

/// Advance the parser by one token
pub fn bump(&mut self) {
if self.last_token_kind == LastTokenKind::Eof {
if self.prev_token_kind == PrevTokenKind::Eof {
// Bumping after EOF is a bad sign, usually an infinite loop.
self.bug("attempted to bump the parser past EOF (may be stuck in a loop)");
}

self.prev_span = self.span;

// Record last token kind for possible error recovery.
self.last_token_kind = match self.token {
token::DocComment(..) => LastTokenKind::DocComment,
token::Comma => LastTokenKind::Comma,
token::Interpolated(..) => LastTokenKind::Interpolated,
token::Eof => LastTokenKind::Eof,
_ => LastTokenKind::Other,
self.prev_token_kind = match self.token {
token::DocComment(..) => PrevTokenKind::DocComment,
token::Comma => PrevTokenKind::Comma,
token::Interpolated(..) => PrevTokenKind::Interpolated,
token::Eof => PrevTokenKind::Eof,
_ => PrevTokenKind::Other,
};

let next = if self.buffer_start == self.buffer_end {
Expand Down Expand Up @@ -976,8 +976,8 @@ impl<'a> Parser<'a> {
self.prev_span = mk_sp(self.span.lo, lo);
// It would be incorrect to record the kind of the current token, but
// fortunately for tokens currently using `bump_with`, the
// last_token_kind will be of no use anyway.
self.last_token_kind = LastTokenKind::Other;
// prev_token_kind will be of no use anyway.
self.prev_token_kind = PrevTokenKind::Other;
self.span = mk_sp(lo, hi);
self.token = next;
self.expected_tokens.clear();
Expand Down Expand Up @@ -2950,7 +2950,7 @@ impl<'a> Parser<'a> {
self.expected_tokens.push(TokenType::Operator);
while let Some(op) = AssocOp::from_token(&self.token) {

let lhs_span = if self.last_token_kind == LastTokenKind::Interpolated {
let lhs_span = if self.prev_token_kind == PrevTokenKind::Interpolated {
self.prev_span
} else {
lhs.span
Expand Down Expand Up @@ -4019,7 +4019,7 @@ impl<'a> Parser<'a> {
None => {
let unused_attrs = |attrs: &[_], s: &mut Self| {
if attrs.len() > 0 {
if s.last_token_kind == LastTokenKind::DocComment {
if s.prev_token_kind == PrevTokenKind::DocComment {
s.span_err_help(s.prev_span,
"found a documentation comment that doesn't document anything",
"doc comments must come before what they document, maybe a \
Expand Down Expand Up @@ -4338,7 +4338,7 @@ impl<'a> Parser<'a> {

let missing_comma = !lifetimes.is_empty() &&
!self.token.is_like_gt() &&
self.last_token_kind != LastTokenKind::Comma;
self.prev_token_kind != PrevTokenKind::Comma;

if missing_comma {

Expand Down