Java regex simple lookaheads#1646
Open
lmasroca wants to merge 32 commits into
Open
Conversation
…regex-simple-assertions # Conflicts: # core/src/main/antlr4/org/evomaster/core/parser/RegexJava.g4 # core/src/main/kotlin/org/evomaster/core/parser/GeneRegexJavaVisitor.kt
lmasroca
commented
Jul 20, 2026
|
|
||
| internal class RegexHandlerTest{ | ||
|
|
||
| @Disabled("Needs to hande lookahead in regex") |
Collaborator
Author
There was a problem hiding this comment.
This test needed (?iu), which is not actually lookahead but embedded flags (in particular Unicode case insensitive), which we support already.
jgaleotti
requested changes
Jul 21, 2026
| override val canBeZeroWidth: Boolean = false | ||
|
|
||
| override fun tryForce(value: String): Int { | ||
| require(value.isNotEmpty()) |
Collaborator
There was a problem hiding this comment.
is this require always used? does it throw illegalArgumentException if not satisfied?
Collaborator
Author
There was a problem hiding this comment.
require(value: Boolean) throws IllegalArgumentException when value is false, no-op if value is true. Here it should always be true unless we have a bug, as tryForce's call sites should not allow this.
Collaborator
Author
There was a problem hiding this comment.
Should we replace require(bool) usages with if(!bool) throw IllegalArgumentException?
…ding cross-attempt mutation contamination.
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.
Added support for basic java regex lookaheads.
This PR introduces a check to
RegexGenes for which theRegexTypeisJVM, in which we check its randomized value after eachrandomize()for a match against its compiled java pattern. If the sampled value does not match we trigger repairs, which aim at repairing the assertions in the regex. These are repaired by sampling a value from the lookahead's internalDisjunctionListRxGeneand attempting to force that value into the following genes. This is safely done as we check if the genes can actually take that value or not before forcing them. We attempt these repairs a couple of times before giving up and throwing.We still do not support nested lookaheads (nested inside a group or nested within another lookahead) as the repair mechanism can not handle them yet. The current repairs this PR introduces can only repair regex genes that are on the same level as the lookahead itself (the
termsof aDisjunctionRxGene). This also does not yet properly handle multiple concatenated lookaheads as the current repair logic steps over the previous repairs if a new repair is triggered.Note: this PR adds a new gene
AssertionRxGeneas well as a new interfaceRxAbsorbablewhich is implemented by regex genes.