Fix JS regexp tester (WEB-48205)

GitOrigin-RevId: f90744bfdaad84bc8a0dada4cc77a5ad0183bd03
This commit is contained in:
Bas Leijdekkers
2020-11-16 12:05:32 +01:00
committed by intellij-monorepo-bot
parent 81009f77ac
commit 035788aeaa
2 changed files with 11 additions and 3 deletions

View File

@@ -11,6 +11,12 @@ public class RegExpMatch {
private final IntList groups = new IntArrayList();
public RegExpMatch() {}
public RegExpMatch(int start, int end) {
add(start, end);
}
public void add(int start, int end) {
groups.add(start);
groups.add(end);

View File

@@ -51,9 +51,11 @@ public class EcmaScriptRegExpMatcherProvider implements RegExpMatcherProvider {
"var match;\n" +
"\n" +
"var RegExpMatch = Java.type(\"org.intellij.lang.regexp.RegExpMatch\");\n" +
"var prev = null;\n" +
"while ((match = regexp.exec(str)) !== null) {\n" +
" var r = new RegExpMatch();\n" +
" r.add(match.index, regexp.lastIndex);\n" +
" var r = new RegExpMatch(match.index, regexp.lastIndex);\n" +
" if (r.equals(prev)) break;\n" +
" prev = r;\n" +
" result.add(r);\n" +
"}\n" +
"result";
@@ -61,7 +63,7 @@ public class EcmaScriptRegExpMatcherProvider implements RegExpMatcherProvider {
bindings.put("result", new SmartList<>());
@SuppressWarnings("unchecked") final List<RegExpMatch> result = (List<RegExpMatch>)engine.eval(script, bindings);
CheckRegExpForm.setMatches(regExpFile, result);
return RegExpMatchResult.FOUND;
return result.isEmpty() ? RegExpMatchResult.NO_MATCH : RegExpMatchResult.FOUND;
}
catch (Exception e) {
return RegExpMatchResult.BAD_REGEXP;