Repository navigation
feat(core): language inclusion for regular Coregexes. - #324
Merged
Merged
Conversation
New exact language operations on Coregex, decided on a Thompson NFA built from the regex: - `isSubsetOf(Coregex)`: whether every string fully matched by this regex is matched by the other. - `difference(Coregex)`: the shortest string matched by this regex but not by the other. - `intersection(Coregex)`: the shortest string matched by both. The search walks the product of this NFA with the lazily determinized other NFA, pruning pairs with antichains, so subset checks stay fast even with nested repetitions. Non-regular constructs (back references, atomic groups, possessive quantifiers, lookarounds, word boundaries) and ASCII approximations of UNICODE_CHARACTER_CLASS char classes are rejected with UnsupportedOperationException. Anchors (`^`, `\A`, `$`, `\z`, `\Z`) are supported at the input boundary, where they are no-ops under Matcher#matches().
Lookarounds used to be checked by Coregex#match() against the whole input generated before (lookbehind) or after (lookahead), rather than a suffix or prefix of it. Negative lookarounds could generate non-matching strings, e.g. `ba(?<!a)` or `(?!a)[ab]b`, and positive ones failed to generate at all, e.g. `b[ab](?<=a)`, `(?=a)[ab]b` or `ab\b`. Lookarounds are now checked with an NFA: the input generated so far has to match `[\s\S]*body` for lookbehind, the rest of the input has to match `body[\s\S]*` for lookahead. Anchors and word boundaries are encoded with standard lookarounds accordingly. Lookaround bodies have to be regular now: back references, nested lookarounds and possessive quantifiers inside lookarounds are rejected with UnsupportedOperationException.
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.
New exact language operations on Coregex, decided on a Thompson NFA built from the regex:
isSubsetOf(Coregex): whether every string fully matched by this regex is matched by the other.difference(Coregex): the shortest string matched by this regex but not by the other.intersection(Coregex): the shortest string matched by both.The search walks the product of this NFA with the lazily determinized other NFA, pruning pairs with antichains, so subset checks stay fast even with nested repetitions.
Non-regular constructs (back references, atomic groups, possessive quantifiers, lookarounds, word boundaries) and ASCII approximations of UNICODE_CHARACTER_CLASS char classes are rejected with UnsupportedOperationException. Anchors (
^,\A,$,\z,\Z) are supported at the input boundary, where they are no-ops under Matcher#matches().Lookaround generation via NFA.