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

Conversation

nnethercote
Copy link
Contributor

The lexer and parser use unclear names to indicate their positions in the
source code. I propose the following renamings.

Lexer:

pos      -> next_pos      # it's actually the next pos!
last_pos -> pos           # it's actually the current pos!
curr     -> ch            # the current char
curr_is  -> ch_is         # tests the current char
col (unchanged)           # the current column

parser

- last_span       -> prev_span          # the previous token's span
- last_token_kind -> prev_token_kind    # the previous token's kind
- LastTokenKind   -> PrevTokenKind      # ditto (but the type)
- token (unchanged)                     # the current token
- span (unchanged)                      # the current span

Things to note:

  • This proposal removes all uses of "last", which is an unclear word because it
    could mean (a) previous, (b) final, or (c) most recent, i.e. current.
  • The "current" things (ch, col, token, span) consistently lack a prefix. The
    "previous" and "next" things consistently have a prefix.

This is a [breaking-change] for libsyntax.
Likewise, rename LastTokenKind as PrevTokenKind.

This is a [breaking-change] for libsyntax.
This is a [breaking-change] for libsyntax.
This is a [breaking-change] for libsyntax.
Likewise, rename StringReader::curr_is as ch_is.

This is a [breaking-change] for libsyntax.
This commit renames the variables to make it clearer which char each one
refers to. It also slightly reorders and rearranges some statements.
@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@nnethercote
Copy link
Contributor Author

r? eddyb -- you looked at the old versions of these patches in #36470.

Also, this changes the public API of libsyntax, so it needs special handling. cc #31645.

@arielb1
Copy link
Contributor

arielb1 commented Oct 5, 2016

r? @eddyb

Copy link
Member

@eddyb eddyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikomatsakis
Copy link
Contributor

To clarify, we're blocked here on @Manishearth doing some kind of "rollup of plugin-breaking changes"?

/me can't wait for macros 1.1

@Manishearth
Copy link
Member

Serde and diesel moved to syn IIRC.

I'm going to try merging this now, since we haven't had other breaking batch things in a while, and this shouldn't break most of the things out there.

cc @dtolnay @sgrif

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Oct 17, 2016

📌 Commit 94b3659 has been approved by eddyb

@dtolnay
Copy link
Member

dtolnay commented Oct 17, 2016

Yeah libsyntax won't affect Serde anymore. I still appreciate the heads-up because aster and quasi still exist.

@petrochenkov
Copy link
Contributor

I'm going to try merging this now

Yay. This is a useful patch and it'd be nice to have it merged sooner rather than later.

bors added a commit that referenced this pull request Oct 18, 2016
Clarify the positions of the lexer and parser

The lexer and parser use unclear names to indicate their positions in the
source code. I propose the following renamings.

Lexer:
```
pos      -> next_pos      # it's actually the next pos!
last_pos -> pos           # it's actually the current pos!
curr     -> ch            # the current char
curr_is  -> ch_is         # tests the current char
col (unchanged)           # the current column
```
parser
```
- last_span       -> prev_span          # the previous token's span
- last_token_kind -> prev_token_kind    # the previous token's kind
- LastTokenKind   -> PrevTokenKind      # ditto (but the type)
- token (unchanged)                     # the current token
- span (unchanged)                      # the current span
```

Things to note:
- This proposal removes all uses of "last", which is an unclear word because it
  could mean (a) previous, (b) final, or (c) most recent, i.e. current.
- The "current" things (ch, col, token, span) consistently lack a prefix. The
  "previous" and "next" things consistently have a prefix.
@bors
Copy link
Contributor

bors commented Oct 18, 2016

⌛ Testing commit 94b3659 with merge 3543a0f...

@bors bors merged commit 94b3659 into rust-lang:master Oct 18, 2016
@nnethercote nnethercote deleted the rename-Parser-fields branch October 18, 2016 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants