Skip to content

Commit 044fbc0

Browse files
committed
optimize the regexp parser
1 parent de6b219 commit 044fbc0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

javascript/extractor/src/com/semmle/js/parser/RegExpParser.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,16 @@ private RegExpTerm parseCharacterClass() {
497497
return this.finishTerm(new CharacterClass(loc, elements, inverted));
498498
}
499499

500+
private static final List<String> escapeClasses = Arrays.asList("d", "D", "s", "S", "w", "W");
501+
500502
private RegExpTerm parseCharacterClassElement() {
501503
SourceLocation loc = new SourceLocation(pos());
502504
RegExpTerm atom = this.parseCharacterClassAtom();
503-
for (String c : Arrays.asList("d", "D", "s", "S", "w", "W")) {
504-
if (this.lookahead("-\\" + c))
505-
return atom;
505+
if (this.lookahead("-\\")) {
506+
for (String c : escapeClasses) {
507+
if (this.lookahead("-\\" + c))
508+
return atom;
509+
}
506510
}
507511
if (!this.lookahead("-]") && this.match("-") && !(atom instanceof CharacterClassEscape))
508512
return this.finishTerm(new CharacterClassRange(loc, atom, this.parseCharacterClassAtom()));

0 commit comments

Comments
 (0)