Skip to content

Rename lexer state to match what it holds#277

Open
git-hulk wants to merge 1 commit into
masterfrom
lexer-naming
Open

Rename lexer state to match what it holds#277
git-hulk wants to merge 1 commit into
masterfrom
lexer-naming

Conversation

@git-hulk

Copy link
Copy Markdown
Member

Summary

Internal naming cleanup, no behavior change. l.lastToken and p.last() actually hold the current lookahead token — the one the parser is looking at but has not consumed yet — not a previously-consumed token. And l.current held the input byte offset, not a token.

Before After
lexerState.current (int) offset
lexerState.lastToken current
Parser.last() cur()
Parser.lastTokenKind() curTokenKind()
Parser.lastTokenString() curTokenString()
local lastToken vars in parser files curToken

The one token that genuinely is the previous one — the local in Lexer.consumeToken used to disambiguate unary +/- from binary — is now named prevToken.

Also gives TokenKindDot its missing TokenKind type annotation (it was an untyped string constant in an otherwise fully-typed block).

All renamed identifiers are unexported; the public API is unchanged.

Testing

Full suite passes including -race -compatible.

🤖 Generated with Claude Code

l.lastToken and p.last() actually hold the *current* lookahead token -
the one the parser is looking at but has not consumed - not a
previously-consumed token. Likewise l.current held the input byte
offset, not a token. Rename for accuracy, no behavior change:

- lexerState.current (int)    -> offset
- lexerState.lastToken        -> current
- Parser.last()               -> cur()
- Parser.lastTokenKind()      -> curTokenKind()
- Parser.lastTokenString()    -> curTokenString()
- local `lastToken` vars      -> curToken (parser files)

The one genuinely-previous token - the local in Lexer.consumeToken used
to disambiguate unary +/- - is named prevToken.

Also give TokenKindDot its missing TokenKind type annotation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant