opencode/packages/codemode-rust/conformance/cases/std-regexp-syntax-errors.js
kommander d1cffe8e14 fix(codemode): word RegExp syntax errors as the reference's host does
new RegExp reported regress's errors ('Unbalanced parenthesis'), and
regress accepts a few patterns JavaScriptCore rejects, such as \b* outside
the unicode flags. The new regexp_syntax module ports the error checks of
JavaScriptCore's YarrParser as Bun ships it (escapes, classes, v-mode class
sets and string disjunctions, groups and modifiers, quantifiers, named and
numbered references with the legacy reparse), and finds the first error in
the order that parser meets it, with its message ('missing )', 'nothing to
repeat'). regress answers the Unicode questions: property names and the
characters of group names. A random sample of 9,000 patterns over the three
flag modes matches the reference's validity and message for every one.

It also covers \k inside a class with named groups, which the duplicate
named groups rewrite used to check.
2026-11-18 18:56:11 +01:00

8 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const pats = ["(", ")", "a)", "(?", "(?x)", "(?<", "(?<a", "(?<1a>x)", "(?<a>x)(?<a>y)", "[", "[b-a]", "a**", "*", "+a", "?", "a{2,1}", "a{99999999999}", "{", "}", "]", "a{1", "\\", "a\\", "\\u{110000}", "\\u{zz}", "\\uzz", "\\k<a>", "(?<a>x)\\k<b>", "(?<a>x)\\k<a", "\\k", "\\1", "(a)\\2", "\\c", "\\c1", "\\01", "\\8", "\\-", "\\a", "\\p{Foo}", "\\p{L", "\\P", "[\\d-a]", "[a-\\d]", "[\\w-z]", "(?=a)*", "(?<=a)+", "\\b*", "^*", "$+", "(?i:a", "(?i-i:a)", "(?ii:a)", "(?z:a)", "(?-:a)", "[\\q{a}]", "[a&&b]", "[a--b]", "[[a]", "[a]]", "[a-]", "[(]", "[a&&&b]", "[^\\q{ab}]", "[a--]", "x{2}{3}", "a{,2}", "(?:", "(?:a|b", "a|*", "(*)", "[]]", "\\x", "\\x1", "\\u12", "\\u{12", "[\\u{110000}]", "a{2,", "a{2,3", "\\p{Script=Foo}", "\\p{RGI_Emoji}", "[\\p{RGI_Emoji}--a]", "\\q{a}", "(?<𝒜>.)", "(?<a\\u0062>x)", "(?<\\u{61}>x)\\k<a>"]
const out = []
for (const flags of ["", "u", "v"]) {
for (const p of pats) {
try { new RegExp(p, flags); out.push(flags + " " + JSON.stringify(p) + " ok") } catch (e) { out.push(flags + " " + JSON.stringify(p) + " " + (e.message.match(/\(([^()]*(?:\([^()]*\)[^()]*)*)\)\. To match/) || [, e.message])[1]) }
}
}
return out