Repository navigation
matcher: fix quantifiers that follow a {n,m} repeat - #1306
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
Parser.meta() treated any '?' after a RepeatMatcher as the reluctant
modifier of the repetition. A group whose body ends up as a single
RepeatMatcher, such as (\d{2})?, lost its '?' and became required, so
^v(\d{2})?$ did not match "v". A possessive modifier such as a{2}+ was
parsed as (a{2})+ instead, so ^a{2}+$ matched "aaaa".
Consume the optional '?' or '+' modifier when parsing the {n,m} repeat
so later quantifiers apply to the preceding term as usual.
This branch has not been deployed
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.
Fixes #1305
Parser.meta()treats any?that follows aRepeatMatcheras the reluctant modifier of the repetition and returns the repetition unchanged. A group whose body compiles to a singleRepeatMatcher, such as(\d{2}), takes the same path, so(\d{2})?loses its?and the group becomes required.^v(\d{2})?$does not matchv.A
+after{n,m}is not consumed either, so the possessivea{2}+is parsed as(a{2})+, and^a{2}+$matchesaaaa.Changes
Parser.repeat(), consume an optional?or+modifier directly after the closing}.RepeatMatcheralready matches greedily without backtracking, so both modifiers keep the current matching behavior for the repetition itself.RepeatMatcherspecial case frommeta(), so a?after a group always makes the group optional.repeatInOptionalGroupandrepeatModifierstoAbstractPatternMatcherTest. They compare the results withjava.util.regex.Patternfor all of the matcher test variants.Testing
PatternMatcherTest,CaseInsensitivePatternMatcherTest,ExpandOrPatternMatcherTest,Re2PatternMatcherTest, andRe2CaseInsensitivePatternMatcherTest), for example^v(\d{2})?$ should match vand^a{2}+$ shouldn't match aaaa../gradlew :spectator-api:build(checkstyle, PMD, SpotBugs, license, tests on JDK 8, 17, and 25),./gradlew license, and./gradlew :spectator-reg-atlas:testpass.