Skip to content

Commit 5470ba4

Browse files
committed
Implemented java identity escapes, replacing syntax escapes.
1 parent 45cddff commit 5470ba4

2 files changed

Lines changed: 5 additions & 24 deletions

File tree

core/src/main/antlr4/org/evomaster/core/parser/RegexJava.g4

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ quoteChar
129129
| E
130130
;
131131

132-
//TODO
133132
CharacterEscape
134133
: SLASH ControlEscape
135134
| SLASH 'c' ControlLetter
@@ -138,8 +137,7 @@ CharacterEscape
138137
| SLASH OctalEscapeSequence
139138
| SLASH ('p' | 'P') BRACE_open PCharacterClassEscapeLabel BRACE_close // this is only implemented in Java at the moment
140139
// as on JS this is allowed only while certain flags are enabled
141-
142-
//| IdentityEscape
140+
| SLASH ~[a-zA-Z0-9] // identity escape
143141
;
144142

145143
// Instead of listing all unicode scripts, blocks, etc. the parser allows anything
@@ -164,13 +162,6 @@ fragment ControlLetter
164162
: [?-_a-z]
165163
;
166164

167-
168-
//TODO
169-
//fragment IdentityEscape ::
170-
//SourceCharacter but not IdentifierPart
171-
//<ZWJ>
172-
//<ZWNJ>
173-
174165
//TODO
175166
//DecimalEscape
176167
// //[lookahead ∉ DecimalDigit]
@@ -261,7 +252,6 @@ classEscape
261252
atomEscape
262253
: CharacterClassEscape
263254
| CharacterEscape
264-
| SyntaxEscapes
265255
| BackReference
266256
| NamedBackReference
267257
;
@@ -284,11 +274,6 @@ CharacterClassEscape
284274
: SLASH [dDsSwWvVhH]
285275
;
286276

287-
288-
SyntaxEscapes
289-
: SLASH [^$\\.*+?()[\]{}|/\-,:<>=!]
290-
;
291-
292277
CARET : '^';
293278
DOLLAR : '$';
294279
SLASH : '\\';

core/src/main/kotlin/org/evomaster/core/parser/GeneRegexJavaVisitor.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ class GeneRegexJavaVisitor(externalRegexFlags: RegexFlags = RegexFlags()) : Rege
2828
)
2929

3030
/**
31-
* These are the Java regex syntax characters, all of these can be escaped to be treated as literals.
31+
* None of these can be escaped to be treated as literals. Some may be part of legal escape sequences.
3232
*/
33-
private val allowedSyntaxEscapes = setOf(
34-
'^', '$', '\\', '.', '*', '+', '?',
35-
'(', ')', '[', ']', '{', '}', '|',
36-
'/', '-', ',' ,':', '<', '>', '=', '!'
37-
)
33+
private val notIdentityEscapes = ('a'..'z').toList() + ('A'..'Z').toList() + ('0'..'9').toList()
3834

3935
/**
4036
* Capture groups in order of appearance (1-based index -> list index 0).
@@ -470,7 +466,7 @@ class GeneRegexJavaVisitor(externalRegexFlags: RegexFlags = RegexFlags()) : Rege
470466
} else {
471467
// This case handles the escaped syntax characters, like "\." and "\+", etc. cases
472468
// where '.' and '+', etc. should be treated as regular chars
473-
assert(startText[0] == '\\' && startText[1] in allowedSyntaxEscapes)
469+
assert(startText[0] == '\\' && startText[1] !in notIdentityEscapes)
474470
start = startText[1]
475471
end = start
476472
}
@@ -647,7 +643,7 @@ class GeneRegexJavaVisitor(externalRegexFlags: RegexFlags = RegexFlags()) : Rege
647643
currentFlags
648644
)
649645
}
650-
in allowedSyntaxEscapes -> PatternCharacterBlockGene(txt, txt.substring(1), currentFlags)
646+
!in notIdentityEscapes -> PatternCharacterBlockGene(txt, txt.substring(1), currentFlags)
651647
else -> CharacterClassEscapeRxGene(txt.substring(1), currentFlags)
652648
})
653649
}

0 commit comments

Comments
 (0)