-
Notifications
You must be signed in to change notification settings - Fork 117
Java regex simple lookaheads #1646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmasroca
wants to merge
32
commits into
master
Choose a base branch
from
java-regex-simple-assertions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
c0c09aa
Added new gene: AssertionRxGene.
lmasroca bc2f711
Updated gene count to reflect new gene added.
lmasroca d46545c
Added sampler for new gene.
lmasroca 06bf520
Lowered chance for large trees.
lmasroca c8397fd
Added new interface for assertion repair usage.
lmasroca 44f421d
Added external flags to RegexGene.
lmasroca 655c915
Passed external flags to RegexGene.
lmasroca 0540b2d
Added MultiCharacterRange.contains(Char) method.
lmasroca 7e45828
Added overrides for new interface RxAbsorbable methods for some regex…
lmasroca b0f694b
Updated RxAbsorbable, added some methods and overrides.
lmasroca ac93549
Added lookaheads to java regex grammar.
lmasroca a58d4e2
Added AssertionRepairWalk util and missing RxAbsorbable overrides.
lmasroca 919485d
Removed unused enum.
lmasroca d1ed3a3
Replaced Pair usage with new data class.
lmasroca 9d6df0d
Added check and repair logic to RegexGene for JVM regexes.
lmasroca ef26857
Passed original java regex string with no preprocessing to RegexGene …
lmasroca 7a3aab6
Added a comment.
lmasroca 564235b
Added tests for simple lookaheads.
lmasroca a4d4a9d
Merge remote-tracking branch 'origin/java-regex-quote-bug' into java-…
lmasroca fcfc949
Merge clean-up: re-added lookaheads to the java regex grammar.
lmasroca 714fb6b
Moved java Pattern compilation to RegexGene initialization.
lmasroca 7874c1d
Re-structured lookahead tests.
lmasroca f3b0fed
Made assertion repairs only run when regex contains assertions.
lmasroca 2c22705
Added braces.
lmasroca 736e1f1
Made canBeZeroWidth a "val" instead of "fun".
lmasroca 7f39dd1
Enabled disabled test.
lmasroca 5eaaf78
Cleared up some comments.
lmasroca b28e279
Requested changes.
lmasroca 0986eaa
Requested changes 2: more javadocs.
lmasroca d7c8b87
Merge remote-tracking branch 'origin/master' into java-regex-simple-a…
lmasroca 49ea960
Removed unnecessary code.
lmasroca 972800b
Made repair loop check full absorbability before forcing begins, avoi…
lmasroca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
126 changes: 126 additions & 0 deletions
126
core/src/main/kotlin/org/evomaster/core/search/gene/regex/AssertionRxGene.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package org.evomaster.core.search.gene.regex | ||
|
|
||
| import org.evomaster.core.output.OutputFormat | ||
| import org.evomaster.core.search.gene.Gene | ||
| import org.evomaster.core.search.gene.root.SimpleGene | ||
| import org.evomaster.core.search.gene.utils.GeneUtils | ||
| import org.evomaster.core.search.service.AdaptiveParameterControl | ||
| import org.evomaster.core.search.service.Randomness | ||
| import org.evomaster.core.search.service.mutator.MutationWeightControl | ||
| import org.evomaster.core.search.service.mutator.genemutation.AdditionalGeneMutationInfo | ||
| import org.evomaster.core.search.service.mutator.genemutation.SubsetGeneMutationSelectionStrategy | ||
|
|
||
| /** | ||
| * Represents a zero-width assertion in the regex gene tree. | ||
| * | ||
| * This gene is placed in the tree at the position where the assertion appeared in the | ||
| * source regex. It produces no characters ([getValueAsPrintableString] always returns | ||
| * ""). | ||
| * | ||
| * Repair is triggered from [DisjunctionRxGene.attemptAssertionRepair], invoked by | ||
| * [RegexGene.randomize] after the disjunction's own sampled value is checked against | ||
| * the source pattern and found not to match. | ||
| */ | ||
| class AssertionRxGene( | ||
| /** | ||
| * The assertion's inner disjunction gene, can be null as the disjunction can be unsatisfiable, | ||
| * in that case [innerGene] is null. | ||
| */ | ||
| val innerGene: DisjunctionListRxGene? | ||
|
lmasroca marked this conversation as resolved.
|
||
| ) : RxTerm, SimpleGene("assertion") { | ||
|
|
||
| override fun checkForLocallyValidIgnoringChildren(): Boolean = true | ||
|
|
||
| override fun isUnsatisfiable(): Boolean = innerGene == null | ||
|
|
||
| override fun isMutable(): Boolean = innerGene?.isMutable() ?: false | ||
|
|
||
| override fun copyContent(): Gene { | ||
| val copy = AssertionRxGene(innerGene?.copy() as? DisjunctionListRxGene) | ||
| copy.name = this.name | ||
| return copy | ||
| } | ||
|
|
||
| override fun randomize(randomness: Randomness, tryToForceNewValue: Boolean) { | ||
| innerGene?.randomize(randomness, tryToForceNewValue) | ||
| } | ||
|
|
||
| override fun setValueWithRawString(value: String) { | ||
| innerGene?.setFromStringValue(value) | ||
| } | ||
|
|
||
| override fun shallowMutate( | ||
| randomness: Randomness, | ||
| apc: AdaptiveParameterControl, | ||
| mwc: MutationWeightControl, | ||
| selectionStrategy: SubsetGeneMutationSelectionStrategy, | ||
| enableAdaptiveGeneMutation: Boolean, | ||
| additionalGeneMutationInfo: AdditionalGeneMutationInfo? | ||
| ): Boolean { | ||
| return false | ||
| } | ||
|
|
||
| /** | ||
| * Zero-width: never contributes characters to the generated string. | ||
| */ | ||
| override fun getValueAsPrintableString( | ||
| previousGenes: List<Gene>, | ||
| mode: GeneUtils.EscapeMode?, | ||
| targetFormat: OutputFormat?, | ||
| extraCheck: Boolean | ||
| ): String = "" | ||
|
|
||
| /** | ||
| * Returns the value currently sampled from [innerGene], or null if there is no | ||
| * inner gene to sample from. | ||
| */ | ||
| fun sampledInnerValue(): String? { | ||
| if (innerGene == null) { | ||
| return null | ||
| } | ||
| return innerGene.getValueAsPrintableString(targetFormat = null) | ||
| } | ||
|
|
||
| override fun containsSameValueAs(other: Gene): Boolean { | ||
| if (other !is AssertionRxGene) { | ||
| return false | ||
| } | ||
| return sampledInnerValue() == other.sampledInnerValue() | ||
| } | ||
|
|
||
| override fun unsafeCopyValueFrom(other: Gene): Boolean { | ||
| if (other !is AssertionRxGene) { | ||
| return false | ||
| } | ||
| return if (innerGene != null && other.innerGene != null) { | ||
| innerGene.unsafeCopyValueFrom(other.innerGene) | ||
| } else { | ||
| innerGene == null && other.innerGene == null | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Always true: an assertion never renders characters ([getValueAsPrintableString] is | ||
| * always ""), so it can always collapse to zero width. | ||
| * @see [RxAbsorbable.canBeZeroWidth] | ||
| */ | ||
| override val canBeZeroWidth: Boolean = true | ||
|
|
||
| /** | ||
| * Always 0: an assertion never absorbs candidate text into itself, it only supplies a | ||
| * candidate for its siblings to absorb, via [sampledInnerValue]. | ||
| * @see [RxAbsorbable.tryForce] | ||
| */ | ||
| override fun tryForce(value: String): Int { | ||
| require(value.isNotEmpty()) | ||
| return 0 | ||
| } | ||
|
|
||
| /** | ||
| * No-op: already always zero-width, so there's nothing to force. | ||
| * @see [RxAbsorbable.forceZeroWidth] | ||
| */ | ||
| override fun forceZeroWidth() { | ||
| // already always zero-width, nothing to do | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.