Java Regex Refactor - #1745
Open
lmasroca wants to merge 5 commits into
Open
Conversation
…nto CharacterClassEscape.
lmasroca
marked this pull request as ready for review
September 9, 2026 01:05
jgaleotti
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactored Java regex character classes in both grammar and visitor:
CHAR_CLASS_MODE) to avoid having to manually enumerate all the default lexer tokens allowed inclassAtomNoDashin the Java parser. This simplifies that parser rule and allows us to remove code invisitNonemptyClassRangesthat was breaking those default tokens back down into literal characters. This also allows us to remove&&as a default mode lexer token, making it only a token within character classes.\p{...}escapes fromCharacterEscape(which represents one character) intoCharacterClassEscape(which represents predefined character classes), since\p{...}escapes represent predefined character classes.classEscapehave its own behavior instead of wrappingatomEscape, and extracted shared code into a method used by both. This simplifiesvisitClassEscapeby skipping having to throw on back references since those are now rejected at lexer level (see related note below) as now back references no longer have a token on that context (CHAR_CLASS_MODE).Note: Since one of the new tests checks that
[\1]is rejected at the lexer level,RegexHandler.ThrowingErrorListener.syntaxError(...)had to be updated. That method declaredoffendingSymbol: Any, but it is actuallynullwhen a lexer error is thrown (as there is no symbol at that point), so we changed it toAny?.