Skip to content
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

JS: Add ECMAScript 2024 v Flag Operators for Regex Parsing #18899

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Exposed flags to the regex parser
  • Loading branch information
Napalys committed Mar 2, 2025
commit cb448db3cecd3da168800d41460d706cbfdd9c5f
Original file line number Diff line number Diff line change
@@ -600,7 +600,7 @@ public Label visit(Literal nd, Context c) {
SourceMap sourceMap =
SourceMap.legacyWithStartPos(
SourceMap.fromString(nd.getRaw()).offsetBy(0, offsets), startPos);
regexpExtractor.extract(source.substring(1, source.lastIndexOf('/')), sourceMap, nd, false);
regexpExtractor.extract(source.substring(1, source.lastIndexOf('/')), sourceMap, nd, false, source.substring(source.lastIndexOf('/'), source.length()));
} else if (nd.isStringLiteral()
&& !c.isInsideType()
&& nd.getRaw().length() < 1000
Original file line number Diff line number Diff line change
@@ -346,8 +346,8 @@ public void visit(CharacterClassRange nd) {
}
}

public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing) {
Result res = parser.parse(src);
public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing, String flags) {
Result res = parser.parse(src, flags);
if (isSpeculativeParsing && res.getErrors().size() > 0) {
return;
}
@@ -364,4 +364,8 @@ public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpec
this.emitLocation(err, lbl);
}
}

public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing) {
extract(src, sourceMap, parent, isSpeculativeParsing, "");
}
}
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ public List<Error> getErrors() {
private List<Error> errors;
private List<BackReference> backrefs;
private int maxbackref;
private String flags;

/** Parse the given string as a regular expression. */
public Result parse(String src) {
@@ -82,6 +83,11 @@ public Result parse(String src) {
return new Result(root, errors);
}

public Result parse(String src, String flags) {
this.flags = flags;
return parse(src);
}

private static String fromCodePoint(int codepoint) {
if (Character.isValidCodePoint(codepoint)) return new String(Character.toChars(codepoint));
// replacement character