Skip to content

Use the NFA start state of the lexical state a string literal is matched in - #13

Open
henrib wants to merge 1 commit into
javacc:releasefrom
henrib:lexical-states-fixes
Open

henrib wants to merge 1 commit into
javacc:releasefrom
henrib:lexical-states-fixes

Conversation

@henrib

@henrib henrib commented Nov 18, 2026

Copy link
Copy Markdown

Fixes javacc/javacc-8#8 for the Java generator: the stringLiterals table of the generated token manager now holds, for each literal of each lexical state, the NFA start state of that lexical state, through TokenizerData.getNfaStartState(lexState, kind).

This needs javacc/javacc-8-core#8: it does not compile against core 8.1.0, so javacc.core.version has to point at a core that includes it before this can be merged.

Checked by building against the patched core: the token managers generated for the issues, examples and grammars of this repository are byte for byte the same as before (none of them has a literal continued differently in two lexical states), and the Commons JEXL grammar gets the same token streams as with JavaCC 7.

🤖 Generated with Claude Code

…hed in

The literal table held, for each literal of each lexical state, the NFA
start state recorded for its kind, which is the one of the lexical state
processed last. A literal declared in more than one lexical state (<*> for
instance) then continued in the NFA of another lexical state.

Uses TokenizerData.getNfaStartState(lexState, kind), which requires a core
that has it.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 18:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new call to TokenizerData.getNfaStartState(int, int) is unavailable in the default core dependency version 8.1.0, preventing compilation until the dependency is updated.

1 open issue
What changed in this PR

Updates the Java token-manager generator so string literals use the NFA start state of their lexical state, addressing literals that continue differently across lexical states.

Changes:

  • Replaces the token-kind-only lookup with getNfaStartState(key >> 16, kind), passing both lexical state and token kind to the core API.
File Description
src/​main/​java/​org/​javacc/​java/​TokenManagerCodeGenerator.java Emits lexical-state-specific NFA start states in the generated string-literal table.

Review effort: Balanced

}
jcb.print(", " + kind);
jcb.print(", " + tokenizerData.kindToNfaStartState.get(kind));
jcb.print(", " + tokenizerData.getNfaStartState(key >> 16, kind));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, as the description says, this depends on javacc/javacc-8-core#8. javacc.core.version is defined in the parent pom (javacc/javacc-8), so it cannot be changed from this repository; it needs a core release or snapshot that has the accessor.

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.

A string literal declared in several lexical states continues in the NFA of only one of them

2 participants