Java regex simple lookaheads#1646
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
|
|
||
| internal class RegexHandlerTest{ | ||
|
|
||
| @Disabled("Needs to hande lookahead in regex") |
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.
| override val canBeZeroWidth: Boolean = false | ||
|
|
||
| override fun tryForce(value: String): Int { | ||
| require(value.isNotEmpty()) |
There was a problem hiding this comment.
is this require always used? does it throw illegalArgumentException if not satisfied?
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.
There was a problem hiding this comment.
Should we replace require(bool) usages with if(!bool) throw IllegalArgumentException?
…ding cross-attempt mutation contamination.
| override val canBeZeroWidth: Boolean = false | ||
|
|
||
| override fun tryForce(value: String): Int { | ||
| require(value.isNotEmpty()) |
| * The assertion's inner disjunction gene, can be null as the disjunction can be unsatisfiable, | ||
| * in that case [innerGene] is null. | ||
| */ | ||
| val innerGene: DisjunctionListRxGene? |
There was a problem hiding this comment.
is the handling of this inner gene correct? i don't see passed as input to parent's constructor, nor added directly to children in an init method
| * in that case [innerGene] is null. | ||
| */ | ||
| val innerGene: DisjunctionListRxGene? | ||
| ) : RxTerm, SimpleGene("assertion") { |
There was a problem hiding this comment.
the use of SimpleGene here seems incorrect, as this gene has a innerGene
There was a problem hiding this comment.
Should this be a CompositeFixedGene instead? If so how would we handle innerGene being null?
There was a problem hiding this comment.
i guess could use CompositeGene?
There was a problem hiding this comment.
Okay, we can probably use listOfNotNull(innerGene) and CompositeGene (or CompositeFixedGene if we allow it to be childless, as once created the number of children does not mutate). Should the same be done for BackReferenceRxGene too?
There was a problem hiding this comment.
For now made both AssertionRxGene and BackReferenceRxGene both extend CompositeFixedGene with canBeChildless() = true, as separate commits. These use listOfNotNull(nullableGene) to set their children (either no children or a single child).
There was a problem hiding this comment.
Reverted the BackReferenceRxGene extending CompositeFixedGene (instead of SimpleGene) commit.
AssertionRxGene owns its innerGene while BackReferenceRxGene does not own its captureGroup, it is just a reference to a DisjunctionListRxGene that exists elsewhere in the regex gene tree.
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.