@oseo/compiler 0.1.0-canary.0 → 0.1.0-canary.370
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -165
- package/dist/agent-programs.d.ts.map +1 -1
- package/dist/agent-programs.js.map +1 -1
- package/dist/agent-templates.d.ts.map +1 -1
- package/dist/agent-templates.js.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js.map +1 -1
- package/dist/fragments.d.ts.map +1 -1
- package/dist/fragments.js.map +1 -1
- package/dist/hir-build.d.ts.map +1 -1
- package/dist/hir-build.js.map +1 -1
- package/dist/hir-print.d.ts.map +1 -1
- package/dist/hir-print.js.map +1 -1
- package/dist/hir.d.ts.map +1 -1
- package/dist/hir.js.map +1 -1
- package/dist/host-scripts.d.ts.map +1 -1
- package/dist/host-scripts.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mir-build.d.ts.map +1 -1
- package/dist/mir-build.js.map +1 -1
- package/dist/mir-print.d.ts.map +1 -1
- package/dist/mir-print.js.map +1 -1
- package/dist/mir-specialize.d.ts.map +1 -1
- package/dist/mir-specialize.js.map +1 -1
- package/dist/mir.d.ts.map +1 -1
- package/dist/module-builtin.d.ts.map +1 -1
- package/dist/module-builtin.js.map +1 -1
- package/dist/module-compile.d.ts.map +1 -1
- package/dist/module-compile.js.map +1 -1
- package/dist/module-json.d.ts.map +1 -1
- package/dist/module-json.js.map +1 -1
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js.map +1 -1
- package/dist/native-fragments.d.ts.map +1 -1
- package/dist/native-fragments.js.map +1 -1
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js.map +1 -1
- package/dist/regexp-execute.d.ts.map +1 -1
- package/dist/regexp-execute.js.map +1 -1
- package/dist/regexp-matcher.d.ts.map +1 -1
- package/dist/regexp-matcher.js.map +1 -1
- package/dist/regexp-parse.d.ts.map +1 -1
- package/dist/regexp-parse.js.map +1 -1
- package/dist/regexp-print.d.ts.map +1 -1
- package/dist/regexp-print.js.map +1 -1
- package/dist/regexp.d.ts.map +1 -1
- package/dist/regexp.js.map +1 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js.map +1 -1
- package/dist/syntax.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexp-execute.js","names":[],"sources":["../src/regexp-execute.ts"],"sourcesContent":["import { checkRegExpMatcherBound } from \"./regexp-matcher.ts\";\nimport type {\n RegExpMatcherCanonicalization,\n RegExpMatcherProgram,\n RegExpMatcherSet,\n} from \"./regexp-matcher.ts\";\nimport type { RegExpSpan } from \"./regexp.ts\";\n\n/** One owned resource boundary the executor can reach. */\nexport type RegExpExecutionLimit =\n | \"backtrack-entries\"\n | \"steps\"\n | \"trail-entries\";\n\n/**\n * Owned boundaries applied while one match attempt runs.\n *\n * ECMA-262 bounds none of these. Reaching one is an owned failure that the\n * caller observes: the executor never returns a wrong match, and never\n * stops on a clock, so the same artifact, input, and limits always produce\n * the same answer on every host and target.\n */\nexport interface RegExpExecutionLimits {\n readonly backtrackEntries: number;\n readonly steps: number;\n readonly trailEntries: number;\n}\n\n/** The reviewed default execution limits. */\nexport const defaultRegExpExecutionLimits: RegExpExecutionLimits = {\n backtrackEntries: 0x40_0000,\n steps: 0x100_0000,\n trailEntries: 0x40_0000,\n};\n\n/** One match attempt over one artifact. */\nexport interface RegExpExecutionInput {\n readonly limits?: RegExpExecutionLimits;\n readonly program: RegExpMatcherProgram;\n readonly startIndex: number;\n readonly text: string;\n}\n\n/**\n * One successful match.\n *\n * `captures[0]` is the whole match and `captures[index]` is capturing\n * group `index`, which is undefined when the group did not participate.\n * Every span is a half-open range of UTF-16 code units into the input.\n */\nexport interface RegExpMatchedExecution {\n readonly captures: readonly (RegExpSpan | undefined)[];\n readonly outcome: \"matched\";\n readonly steps: number;\n}\n\n/** One attempt that completed with no match. */\nexport interface RegExpUnmatchedExecution {\n readonly outcome: \"unmatched\";\n readonly steps: number;\n}\n\n/** One attempt that reached an owned resource boundary. */\nexport interface RegExpLimitedExecution {\n readonly limit: RegExpExecutionLimit;\n readonly outcome: \"limit\";\n readonly steps: number;\n}\n\n/** The outcome of one match attempt. */\nexport type RegExpExecution =\n | RegExpLimitedExecution\n | RegExpMatchedExecution\n | RegExpUnmatchedExecution;\n\n/** An unset capture register. */\nconst unset = -1;\n\n/**\n * Reject a request a caller built wrong.\n *\n * A start position that is not a safe integer is not a position at all,\n * and a limit that is not a count would silently disable the boundary it\n * names. Both are caller defects, so both throw rather than producing a\n * match state derived from them. A start position outside the input is a\n * defined query with a defined answer and stays an ordinary outcome.\n */\nfunction checkRequest(request: RegExpExecutionInput): RegExpExecutionLimits {\n if (!Number.isSafeInteger(request.startIndex)) {\n throw new RangeError(\"A start position must be a safe integer.\");\n }\n const limits = request.limits ?? defaultRegExpExecutionLimits;\n checkRegExpMatcherBound(limits.backtrackEntries, \"A backtrack-entry limit\");\n checkRegExpMatcherBound(limits.steps, \"A step limit\");\n checkRegExpMatcherBound(limits.trailEntries, \"A trail-entry limit\");\n return limits;\n}\n\n/** Whether one inversion list holds one character. */\nfunction setHas(set: RegExpMatcherSet, character: number): boolean {\n let low = 0;\n let high = set.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n if ((set[middle] ?? 0) <= character) low = middle + 1;\n else high = middle;\n }\n return (low & 1) === 1;\n}\n\nfunction canonicalize(\n table: RegExpMatcherCanonicalization | undefined,\n character: number,\n): number {\n if (table == null) return character;\n const characters = table.characters;\n let low = 0;\n let high = characters.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const value = characters[middle] ?? 0;\n if (value === character) return table.canonical[middle] ?? character;\n if (value < character) low = middle + 1;\n else high = middle;\n }\n return character;\n}\n\n/**\n * One character of the input read forward from `index`.\n *\n * A pattern with `u` or `v` matches a list of code points and every other\n * pattern matches a list of UTF-16 code units, which is the only place the\n * flag set changes what one position advances by. A lone surrogate is one\n * character in both readings.\n */\nfunction characterAt(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n const unit = text.charCodeAt(index);\n if (!unicodeMode || unit < 0xd8_00 || unit > 0xdb_ff) return unit;\n const trail = text.charCodeAt(index + 1);\n if (Number.isNaN(trail) || trail < 0xdc_00 || trail > 0xdf_ff) return unit;\n return (unit - 0xd8_00) * 0x4_00 + (trail - 0xdc_00) + 0x1_00_00;\n}\n\n/** How many code units the character starting at `index` occupies. */\nfunction widthAt(text: string, index: number, unicodeMode: boolean): number {\n return characterAt(text, index, unicodeMode) > 0xff_ff ? 2 : 1;\n}\n\n/** How many code units the character ending at `index` occupies. */\nfunction widthBefore(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n if (!unicodeMode || index < 2) return 1;\n const trail = text.charCodeAt(index - 1);\n const lead = text.charCodeAt(index - 2);\n const paired =\n trail >= 0xdc_00 && trail <= 0xdf_ff && lead >= 0xd8_00 && lead <= 0xdb_ff;\n return paired ? 2 : 1;\n}\n\n/** The character ending at `index`, or -1 at the start of the input. */\nfunction characterBefore(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n if (index <= 0) return -1;\n return characterAt(\n text,\n index - widthBefore(text, index, unicodeMode),\n unicodeMode,\n );\n}\n\n/**\n * The position one attempt actually starts at.\n *\n * The edition converts a string index into an index into the character\n * list it matches over, and under `u` or `v` both code units of a\n * surrogate pair belong to the one character they encode. A start index\n * that splits a pair therefore names that character, not its trailing\n * code unit, so the attempt begins at the pair.\n */\nfunction alignedStart(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n if (!unicodeMode || index <= 0 || index >= text.length) return index;\n const trail = text.charCodeAt(index);\n const lead = text.charCodeAt(index - 1);\n const paired =\n trail >= 0xdc_00 && trail <= 0xdf_ff && lead >= 0xd8_00 && lead <= 0xdb_ff;\n return paired ? index - 1 : index;\n}\n\n/** The four code points the LineTerminator production names. */\nfunction isLineTerminator(character: number): boolean {\n return (\n character === 0x0a ||\n character === 0x0d ||\n character === 0x20_28 ||\n character === 0x20_29\n );\n}\n\n/**\n * The mutable state of one attempt.\n *\n * Every register write is recorded on a trail, so one backtrack entry\n * restores the whole state by truncating the trail to a recorded height\n * rather than by copying the registers. Both stacks are explicit and\n * checked, so a deeply backtracking pattern reports an owned limit instead\n * of consuming a native call stack.\n */\ninterface Machine {\n readonly limits: RegExpExecutionLimits;\n readonly program: RegExpMatcherProgram;\n readonly registers: number[];\n readonly stackIndex: number[];\n readonly stackProgram: number[];\n readonly stackTrail: number[];\n readonly text: string;\n readonly trailRegister: number[];\n readonly trailValue: number[];\n readonly unicodeMode: boolean;\n index: number;\n limit: RegExpExecutionLimit | undefined;\n steps: number;\n}\n\nfunction write(machine: Machine, register: number, value: number): boolean {\n if (machine.trailRegister.length >= machine.limits.trailEntries) {\n machine.limit = \"trail-entries\";\n return false;\n }\n machine.trailRegister.push(register);\n machine.trailValue.push(machine.registers[register] ?? unset);\n machine.registers[register] = value;\n return true;\n}\n\nfunction undoTrail(machine: Machine, height: number): void {\n while (machine.trailRegister.length > height) {\n const register = machine.trailRegister.pop() ?? 0;\n machine.registers[register] = machine.trailValue.pop() ?? unset;\n }\n}\n\nfunction push(machine: Machine, address: number): boolean {\n if (machine.stackProgram.length >= machine.limits.backtrackEntries) {\n machine.limit = \"backtrack-entries\";\n return false;\n }\n machine.stackProgram.push(address);\n machine.stackIndex.push(machine.index);\n machine.stackTrail.push(machine.trailRegister.length);\n return true;\n}\n\n/** The address one backtrack entry resumes at, or -1 when none is left. */\nfunction pop(machine: Machine): number {\n const address = machine.stackProgram.pop();\n if (address == null) return -1;\n machine.index = machine.stackIndex.pop() ?? 0;\n undoTrail(machine, machine.stackTrail.pop() ?? 0);\n return address;\n}\n\n/**\n * The outcome of one backreference, with the steps a lowering charges.\n *\n * A lowering writes one instruction per candidate capture, so `steps` is\n * how many of those a native program executes: every candidate when the\n * reference succeeds, because a capture that did not participate matches\n * the empty string, and only the candidates up to and including the one\n * that failed otherwise. `limited` reports that the step budget ran out\n * before a candidate could run, which is where a lowered program stops.\n * Charging that here is what keeps the artifact's reviewed step limit a\n * bound on the lowered program rather than on this array's length.\n */\ninterface BackreferenceAttempt {\n readonly limited: boolean;\n readonly matched: boolean;\n readonly steps: number;\n}\n\n/**\n * Match one backreference, or report that the path fails.\n *\n * The candidates run one at a time, in the order a lowering writes them,\n * and `allowed` is how many of them the remaining step budget admits, so\n * a request with one step left reads one candidate rather than the whole\n * list. A candidate whose capture did not participate matches the empty\n * string; the edition lets at most one of them participate, and running\n * each in turn is what makes that a consequence rather than an\n * assumption.\n */\nfunction matchBackreference(\n machine: Machine,\n slots: readonly number[],\n backward: boolean,\n ignoreCase: boolean,\n allowed: number,\n): BackreferenceAttempt {\n const total = Math.max(slots.length, 1);\n const table = ignoreCase ? machine.program.canonicalization : undefined;\n for (let candidate = 0; candidate < total; candidate += 1) {\n if (candidate >= allowed) {\n return { limited: true, matched: false, steps: allowed };\n }\n const refused = { limited: false, matched: false, steps: candidate + 1 };\n const slot = slots[candidate];\n if (slot == null) continue;\n const start = machine.registers[slot] ?? unset;\n const end = machine.registers[slot + 1] ?? unset;\n if (start === unset || end === unset) continue;\n const length = end - start;\n const target = backward ? machine.index - length : machine.index;\n if (target < 0 || target + length > machine.text.length) return refused;\n let source = start;\n let compared = target;\n let equal = true;\n while (source < end) {\n const width = widthAt(machine.text, source, machine.unicodeMode);\n const left = characterAt(machine.text, source, machine.unicodeMode);\n const right = characterAt(machine.text, compared, machine.unicodeMode);\n if (canonicalize(table, left) !== canonicalize(table, right)) {\n equal = false;\n break;\n }\n source += width;\n compared += width;\n }\n if (!equal) return refused;\n machine.index = backward ? target : target + length;\n }\n return { limited: false, matched: true, steps: total };\n}\n\nfunction matchesBoundary(machine: Machine, set: RegExpMatcherSet): boolean {\n const before = characterBefore(\n machine.text,\n machine.index,\n machine.unicodeMode,\n );\n const wordBefore = before >= 0 && setHas(set, before);\n const wordAfter =\n machine.index < machine.text.length &&\n setHas(set, characterAt(machine.text, machine.index, machine.unicodeMode));\n return wordBefore !== wordAfter;\n}\n\nfunction matchesEdge(\n machine: Machine,\n assertion: \"end\" | \"start\",\n multiline: boolean,\n): boolean {\n if (assertion === \"start\") {\n if (machine.index === 0) return true;\n if (!multiline) return false;\n return isLineTerminator(\n characterBefore(machine.text, machine.index, machine.unicodeMode),\n );\n }\n if (machine.index === machine.text.length) return true;\n if (!multiline) return false;\n return isLineTerminator(\n characterAt(machine.text, machine.index, machine.unicodeMode),\n );\n}\n\nfunction collectCaptures(\n machine: Machine,\n): readonly (RegExpSpan | undefined)[] {\n const total = machine.program.captures.length + 1;\n const captures: (RegExpSpan | undefined)[] = [];\n for (let index = 0; index < total; index += 1) {\n const start = machine.registers[2 * index] ?? unset;\n const end = machine.registers[2 * index + 1] ?? unset;\n captures.push(\n start === unset || end === unset ? undefined : { end, start },\n );\n }\n return captures;\n}\n\n/**\n * Prove the entire artifact is ^set+$ before touching match state.\n *\n * Keep this exact layout proof in sync with anchored_repeat_set in C.\n * There is no continuation, capture, empty body or alternative whose\n * state could escape the scan. Everything else keeps ordered execution.\n */\nfunction anchoredRepeatSet(\n program: RegExpMatcherProgram,\n): RegExpMatcherSet | undefined {\n if (\n ![\"\", \"u\", \"v\"].includes(program.flags.text) ||\n program.captures.length !== 0 ||\n program.registers !== 4 ||\n program.instructions.length !== 11\n )\n return undefined;\n const [\n save,\n start,\n init,\n repeat,\n enter,\n consume,\n end,\n edge,\n close,\n accept,\n fail,\n ] = program.instructions;\n if (\n save?.kind !== \"save\" ||\n save.slot !== 0 ||\n start?.kind !== \"edge\" ||\n start.assertion !== \"start\" ||\n start.multiline ||\n init?.kind !== \"repeat-init\" ||\n init.counter !== 2 ||\n repeat?.kind !== \"repeat\" ||\n repeat.counter !== 2 ||\n repeat.enter !== 4 ||\n repeat.exit !== 7 ||\n !repeat.greedy ||\n repeat.minimum !== 1 ||\n repeat.maximum !== Infinity ||\n enter?.kind !== \"repeat-enter\" ||\n enter.counter !== 2 ||\n enter.position !== 3 ||\n enter.body !== 5 ||\n enter.clearFrom !== 0 ||\n enter.clearTo !== 0 ||\n consume?.kind !== \"consume\" ||\n consume.backward ||\n end?.kind !== \"repeat-end\" ||\n end.counter !== 2 ||\n end.position !== 3 ||\n end.head !== 3 ||\n end.minimum !== 1 ||\n edge?.kind !== \"edge\" ||\n edge.assertion !== \"end\" ||\n edge.multiline ||\n close?.kind !== \"save\" ||\n close.slot !== 1 ||\n accept?.kind !== \"accept\" ||\n fail?.kind !== \"fail\"\n )\n return undefined;\n return program.sets[consume.set];\n}\n\n/**\n * Constant-state scan of a proved complete pattern, with no undo state.\n * Charge one entry, one per character tested, and one terminal decision.\n * The existing step ceiling remains explicit; no trail or stack is used.\n * Non-multiline $ requires InputLength, including after line terminators.\n */\nfunction scanAnchoredRepeat(\n request: RegExpExecutionInput,\n limits: RegExpExecutionLimits,\n set: RegExpMatcherSet,\n): RegExpExecution {\n const { program, text } = request;\n let steps = 0;\n const limited = (): RegExpLimitedExecution => ({\n limit: \"steps\",\n outcome: \"limit\",\n steps,\n });\n if (steps >= limits.steps) return limited();\n steps += 1;\n if (alignedStart(text, request.startIndex, program.unicodeMode) !== 0) {\n return { outcome: \"unmatched\", steps };\n }\n let index = 0;\n while (index < text.length) {\n if (steps >= limits.steps) return limited();\n steps += 1;\n const character = characterAt(text, index, program.unicodeMode);\n if (!setHas(set, character)) return { outcome: \"unmatched\", steps };\n index += character > 0xff_ff ? 2 : 1;\n }\n if (steps >= limits.steps) return limited();\n steps += 1;\n return index === 0\n ? { outcome: \"unmatched\", steps }\n : {\n captures: [{ end: index, start: 0 }],\n outcome: \"matched\",\n steps,\n };\n}\n\n/**\n * Run one anchored match attempt at one position.\n *\n * The attempt starts at `startIndex` and never searches a later position;\n * `searchRegExpMatcher` owns that loop. Under `u` or `v` a start index\n * that splits a surrogate pair names the character the pair encodes, so\n * the attempt begins at the pair rather than at its trailing code unit.\n */\nexport function matchRegExpMatcher(\n request: RegExpExecutionInput,\n): RegExpExecution {\n const { program, startIndex, text } = request;\n const limits = checkRequest(request);\n if (startIndex < 0 || startIndex > text.length) {\n return { outcome: \"unmatched\", steps: 0 };\n }\n const scanSet = anchoredRepeatSet(program);\n if (scanSet != null) return scanAnchoredRepeat(request, limits, scanSet);\n const machine: Machine = {\n index: alignedStart(text, startIndex, program.unicodeMode),\n limit: undefined,\n limits,\n program,\n registers: Array.from({ length: program.registers }, () => unset),\n stackIndex: [],\n stackProgram: [],\n stackTrail: [],\n steps: 0,\n text,\n trailRegister: [],\n trailValue: [],\n unicodeMode: program.unicodeMode,\n };\n for (\n let index = 2 * (program.captures.length + 1);\n index < program.registers;\n index += 1\n ) {\n machine.registers[index] = 0;\n }\n let address = 0;\n for (;;) {\n if (machine.steps >= limits.steps) {\n return { limit: \"steps\", outcome: \"limit\", steps: machine.steps };\n }\n machine.steps += 1;\n const instruction = program.instructions[address];\n if (instruction == null) {\n return { outcome: \"unmatched\", steps: machine.steps };\n }\n let failed = false;\n if (instruction.kind === \"accept\") {\n return {\n captures: collectCaptures(machine),\n outcome: \"matched\",\n steps: machine.steps,\n };\n } else if (instruction.kind === \"consume\") {\n const width = instruction.backward\n ? widthBefore(text, machine.index, machine.unicodeMode)\n : widthAt(text, machine.index, machine.unicodeMode);\n const at = instruction.backward ? machine.index - width : machine.index;\n const next = instruction.backward ? at : machine.index + width;\n const set = program.sets[instruction.set] ?? [];\n if (\n at < 0 ||\n at >= text.length ||\n next < 0 ||\n next > text.length ||\n !setHas(set, characterAt(text, at, machine.unicodeMode))\n ) {\n failed = true;\n } else {\n machine.index = next;\n address += 1;\n }\n } else if (instruction.kind === \"edge\") {\n if (matchesEdge(machine, instruction.assertion, instruction.multiline)) {\n address += 1;\n } else failed = true;\n } else if (instruction.kind === \"boundary\") {\n const set = program.sets[instruction.set] ?? [];\n if (matchesBoundary(machine, set) !== instruction.negated) address += 1;\n else failed = true;\n } else if (instruction.kind === \"save\") {\n if (!write(machine, instruction.slot, machine.index)) {\n return limitReached(machine);\n }\n address += 1;\n } else if (instruction.kind === \"clear\") {\n for (let slot = instruction.from; slot < instruction.to; slot += 1) {\n if (!write(machine, slot, unset)) return limitReached(machine);\n }\n address += 1;\n } else if (instruction.kind === \"fork\") {\n if (!push(machine, instruction.alternative)) {\n return limitReached(machine);\n }\n address = instruction.preferred;\n } else if (instruction.kind === \"jump\") {\n address = instruction.target;\n } else if (instruction.kind === \"repeat\") {\n const done = machine.registers[instruction.counter] ?? 0;\n if (done < instruction.minimum) address = instruction.enter;\n else if (done >= instruction.maximum) address = instruction.exit;\n else if (instruction.greedy) {\n if (!push(machine, instruction.exit)) return limitReached(machine);\n address = instruction.enter;\n } else {\n if (!push(machine, instruction.enter)) return limitReached(machine);\n address = instruction.exit;\n }\n } else if (instruction.kind === \"repeat-init\") {\n if (!write(machine, instruction.counter, 0)) return limitReached(machine);\n address += 1;\n } else if (instruction.kind === \"repeat-enter\") {\n const done = machine.registers[instruction.counter] ?? 0;\n if (!write(machine, instruction.counter, done + 1)) {\n return limitReached(machine);\n }\n if (!write(machine, instruction.position, machine.index)) {\n return limitReached(machine);\n }\n for (\n let slot = instruction.clearFrom;\n slot < instruction.clearTo;\n slot += 1\n ) {\n if (!write(machine, slot, unset)) return limitReached(machine);\n }\n address = instruction.body;\n } else if (instruction.kind === \"repeat-end\") {\n const done = (machine.registers[instruction.counter] ?? 1) - 1;\n const started = machine.registers[instruction.position] ?? unset;\n if (done >= instruction.minimum && started === machine.index) {\n failed = true;\n } else address = instruction.head;\n } else if (instruction.kind === \"look-start\") {\n if (!push(machine, instruction.onFail)) return limitReached(machine);\n if (!write(machine, instruction.frame, machine.stackProgram.length - 1)) {\n return limitReached(machine);\n }\n address = instruction.body;\n } else if (instruction.kind === \"look-end\") {\n const frame = machine.registers[instruction.frame] ?? 0;\n const entryIndex = machine.stackIndex[frame] ?? 0;\n const entryTrail = machine.stackTrail[frame] ?? 0;\n machine.stackProgram.length = frame;\n machine.stackIndex.length = frame;\n machine.stackTrail.length = frame;\n machine.index = entryIndex;\n if (instruction.negated) {\n undoTrail(machine, entryTrail);\n failed = true;\n } else address = instruction.exit;\n } else if (instruction.kind === \"backreference\") {\n // The loop already charged the first candidate, so the budget is\n // that one plus whatever the step limit still admits.\n const attempt = matchBackreference(\n machine,\n instruction.slots,\n instruction.backward,\n instruction.ignoreCase,\n machine.limits.steps - machine.steps + 1,\n );\n machine.steps += attempt.steps - 1;\n if (attempt.limited) {\n return { limit: \"steps\", outcome: \"limit\", steps: machine.steps };\n }\n if (attempt.matched) address += 1;\n else failed = true;\n } else failed = true;\n if (failed) {\n const resumed = pop(machine);\n if (resumed < 0) return { outcome: \"unmatched\", steps: machine.steps };\n address = resumed;\n }\n }\n}\n\nfunction limitReached(machine: Machine): RegExpLimitedExecution {\n return {\n limit: machine.limit ?? \"steps\",\n outcome: \"limit\",\n steps: machine.steps,\n };\n}\n\n/**\n * Search for the first match at or after one position.\n *\n * This is the position loop of the edition's built-in execution without\n * any object state: a sticky pattern attempts only the given position, and\n * every other pattern advances by one character until the input is\n * exhausted. `lastIndex`, the result array, and `exec` dispatch belong to\n * the unit that adds the `RegExp` intrinsic.\n */\nexport function searchRegExpMatcher(\n request: RegExpExecutionInput,\n): RegExpExecution {\n const { program, text } = request;\n const limits = checkRequest(request);\n let steps = 0;\n if (request.startIndex < 0 || request.startIndex > text.length) {\n return { outcome: \"unmatched\", steps: 0 };\n }\n const scanSet = anchoredRepeatSet(program);\n if (scanSet != null) return scanAnchoredRepeat(request, limits, scanSet);\n let index = alignedStart(text, request.startIndex, program.unicodeMode);\n for (;;) {\n const attempt = matchRegExpMatcher({\n limits: {\n backtrackEntries: limits.backtrackEntries,\n steps: limits.steps - steps,\n trailEntries: limits.trailEntries,\n },\n program,\n startIndex: index,\n text,\n });\n steps += attempt.steps;\n if (attempt.outcome === \"matched\") {\n return { captures: attempt.captures, outcome: \"matched\", steps };\n }\n if (attempt.outcome === \"limit\") {\n return { limit: attempt.limit, outcome: \"limit\", steps };\n }\n if (program.flags.sticky || index >= text.length) {\n return { outcome: \"unmatched\", steps };\n }\n index += widthAt(text, index, program.unicodeMode);\n }\n}\n"],"mappings":";;;;AA6BA,MAAa,+BAAsD;CACjE,kBAAkB;CAClB,OAAO;CACP,cAAc;AAChB;;AA2CA,MAAM,QAAQ;;;;;;;;;;AAWd,SAAS,aAAa,SAAsD;CAC1E,IAAI,CAAC,OAAO,cAAc,QAAQ,UAAU,GAC1C,MAAM,IAAI,WAAW,0CAA0C;CAEjE,MAAM,SAAS,QAAQ,UAAU;CACjC,wBAAwB,OAAO,kBAAkB,yBAAyB;CAC1E,wBAAwB,OAAO,OAAO,cAAc;CACpD,wBAAwB,OAAO,cAAc,qBAAqB;CAClE,OAAO;AACT;;AAGA,SAAS,OAAO,KAAuB,WAA4B;CACjE,IAAI,MAAM;CACV,IAAI,OAAO,IAAI;CACf,OAAO,MAAM,MAAM;EACjB,MAAM,SAAU,MAAM,QAAS;EAC/B,KAAK,IAAI,WAAW,MAAM,WAAW,MAAM,SAAS;OAC/C,OAAO;CACd;CACA,QAAQ,MAAM,OAAO;AACvB;AAEA,SAAS,aACP,OACA,WACQ;CACR,IAAI,SAAS,MAAM,OAAO;CAC1B,MAAM,aAAa,MAAM;CACzB,IAAI,MAAM;CACV,IAAI,OAAO,WAAW;CACtB,OAAO,MAAM,MAAM;EACjB,MAAM,SAAU,MAAM,QAAS;EAC/B,MAAM,QAAQ,WAAW,WAAW;EACpC,IAAI,UAAU,WAAW,OAAO,MAAM,UAAU,WAAW;EAC3D,IAAI,QAAQ,WAAW,MAAM,SAAS;OACjC,OAAO;CACd;CACA,OAAO;AACT;;;;;;;;;AAUA,SAAS,YACP,MACA,OACA,aACQ;CACR,MAAM,OAAO,KAAK,WAAW,KAAK;CAClC,IAAI,CAAC,eAAe,OAAO,SAAW,OAAO,OAAS,OAAO;CAC7D,MAAM,QAAQ,KAAK,WAAW,QAAQ,CAAC;CACvC,IAAI,OAAO,MAAM,KAAK,KAAK,QAAQ,SAA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ACF;AAEA,SAAS,aAAa,SAA0C;CAC9D,OAAO;EACL,OAAO,QAAQ,SAAS;EACxB,SAAS;EACT,OAAO,QAAQ;CACjB;AACF;;;;;;;;;;AAWA,SAAgB,oBACd,SACiB;CACjB,MAAM,EAAE,SAAS,SAAS;CAC1B,MAAM,SAAS,aAAa,OAAO;CACnC,IAAI,QAAQ;CACZ,IAAI,QAAQ,aAAa,KAAK,QAAQ,aAAa,KAAK,QACtD,OAAO;EAAE,SAAS;EAAa,OAAO;CAAE;CAE1C,MAAM,UAAU,kBAAkB,OAAO;CACzC,IAAI,WAAW,MAAM,OAAO,mBAAmB,SAAS,QAAQ,OAAO;CACvE,IAAI,QAAQ,aAAa,MAAM,QAAQ,YAAY,QAAQ,WAAW;CACtE,SAAS;EACP,MAAM,UAAU,mBAAmB;GACjC,QAAQ;IACN,kBAAkB,OAAO;IACzB,OAAO,OAAO,QAAQ;IACtB,cAAc,OAAO;GACvB;GACA;GACA,YAAY;GACZ;EACF,CAAC;EACD,SAAS,QAAQ;EACjB,IAAI,QAAQ,YAAY,WACtB,OAAO;GAAE,UAAU,QAAQ;GAAU,SAAS;GAAW;EAAM;EAEjE,IAAI,QAAQ,YAAY,SACtB,OAAO;GAAE,OAAO,QAAQ;GAAO,SAAS;GAAS;EAAM;EAEzD,IAAI,QAAQ,MAAM,UAAU,SAAS,KAAK,QACxC,OAAO;GAAE,SAAS;GAAa;EAAM;EAEvC,SAAS,QAAQ,MAAM,OAAO,QAAQ,WAAW;CACnD;AACF"}
|
|
1
|
+
{"version":3,"file":"regexp-execute.js","names":[],"sources":["../src/regexp-execute.ts"],"sourcesContent":["/*\n * Oseo, an ahead-of-time compiler for JavaScript and TypeScript.\n * Copyright (C) 2026 Hong Minhee <https://hongminhee.org/>\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\n */\n\nimport { checkRegExpMatcherBound } from \"./regexp-matcher.ts\";\nimport type {\n RegExpMatcherCanonicalization,\n RegExpMatcherProgram,\n RegExpMatcherSet,\n} from \"./regexp-matcher.ts\";\nimport type { RegExpSpan } from \"./regexp.ts\";\n\n/** One owned resource boundary the executor can reach. */\nexport type RegExpExecutionLimit =\n | \"backtrack-entries\"\n | \"steps\"\n | \"trail-entries\";\n\n/**\n * Owned boundaries applied while one match attempt runs.\n *\n * ECMA-262 bounds none of these. Reaching one is an owned failure that the\n * caller observes: the executor never returns a wrong match, and never\n * stops on a clock, so the same artifact, input, and limits always produce\n * the same answer on every host and target.\n */\nexport interface RegExpExecutionLimits {\n readonly backtrackEntries: number;\n readonly steps: number;\n readonly trailEntries: number;\n}\n\n/** The reviewed default execution limits. */\nexport const defaultRegExpExecutionLimits: RegExpExecutionLimits = {\n backtrackEntries: 0x40_0000,\n steps: 0x100_0000,\n trailEntries: 0x40_0000,\n};\n\n/** One match attempt over one artifact. */\nexport interface RegExpExecutionInput {\n readonly limits?: RegExpExecutionLimits;\n readonly program: RegExpMatcherProgram;\n readonly startIndex: number;\n readonly text: string;\n}\n\n/**\n * One successful match.\n *\n * `captures[0]` is the whole match and `captures[index]` is capturing\n * group `index`, which is undefined when the group did not participate.\n * Every span is a half-open range of UTF-16 code units into the input.\n */\nexport interface RegExpMatchedExecution {\n readonly captures: readonly (RegExpSpan | undefined)[];\n readonly outcome: \"matched\";\n readonly steps: number;\n}\n\n/** One attempt that completed with no match. */\nexport interface RegExpUnmatchedExecution {\n readonly outcome: \"unmatched\";\n readonly steps: number;\n}\n\n/** One attempt that reached an owned resource boundary. */\nexport interface RegExpLimitedExecution {\n readonly limit: RegExpExecutionLimit;\n readonly outcome: \"limit\";\n readonly steps: number;\n}\n\n/** The outcome of one match attempt. */\nexport type RegExpExecution =\n | RegExpLimitedExecution\n | RegExpMatchedExecution\n | RegExpUnmatchedExecution;\n\n/** An unset capture register. */\nconst unset = -1;\n\n/**\n * Reject a request a caller built wrong.\n *\n * A start position that is not a safe integer is not a position at all,\n * and a limit that is not a count would silently disable the boundary it\n * names. Both are caller defects, so both throw rather than producing a\n * match state derived from them. A start position outside the input is a\n * defined query with a defined answer and stays an ordinary outcome.\n */\nfunction checkRequest(request: RegExpExecutionInput): RegExpExecutionLimits {\n if (!Number.isSafeInteger(request.startIndex)) {\n throw new RangeError(\"A start position must be a safe integer.\");\n }\n const limits = request.limits ?? defaultRegExpExecutionLimits;\n checkRegExpMatcherBound(limits.backtrackEntries, \"A backtrack-entry limit\");\n checkRegExpMatcherBound(limits.steps, \"A step limit\");\n checkRegExpMatcherBound(limits.trailEntries, \"A trail-entry limit\");\n return limits;\n}\n\n/** Whether one inversion list holds one character. */\nfunction setHas(set: RegExpMatcherSet, character: number): boolean {\n let low = 0;\n let high = set.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n if ((set[middle] ?? 0) <= character) low = middle + 1;\n else high = middle;\n }\n return (low & 1) === 1;\n}\n\nfunction canonicalize(\n table: RegExpMatcherCanonicalization | undefined,\n character: number,\n): number {\n if (table == null) return character;\n const characters = table.characters;\n let low = 0;\n let high = characters.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const value = characters[middle] ?? 0;\n if (value === character) return table.canonical[middle] ?? character;\n if (value < character) low = middle + 1;\n else high = middle;\n }\n return character;\n}\n\n/**\n * One character of the input read forward from `index`.\n *\n * A pattern with `u` or `v` matches a list of code points and every other\n * pattern matches a list of UTF-16 code units, which is the only place the\n * flag set changes what one position advances by. A lone surrogate is one\n * character in both readings.\n */\nfunction characterAt(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n const unit = text.charCodeAt(index);\n if (!unicodeMode || unit < 0xd8_00 || unit > 0xdb_ff) return unit;\n const trail = text.charCodeAt(index + 1);\n if (Number.isNaN(trail) || trail < 0xdc_00 || trail > 0xdf_ff) return unit;\n return (unit - 0xd8_00) * 0x4_00 + (trail - 0xdc_00) + 0x1_00_00;\n}\n\n/** How many code units the character starting at `index` occupies. */\nfunction widthAt(text: string, index: number, unicodeMode: boolean): number {\n return characterAt(text, index, unicodeMode) > 0xff_ff ? 2 : 1;\n}\n\n/** How many code units the character ending at `index` occupies. */\nfunction widthBefore(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n if (!unicodeMode || index < 2) return 1;\n const trail = text.charCodeAt(index - 1);\n const lead = text.charCodeAt(index - 2);\n const paired =\n trail >= 0xdc_00 && trail <= 0xdf_ff && lead >= 0xd8_00 && lead <= 0xdb_ff;\n return paired ? 2 : 1;\n}\n\n/** The character ending at `index`, or -1 at the start of the input. */\nfunction characterBefore(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n if (index <= 0) return -1;\n return characterAt(\n text,\n index - widthBefore(text, index, unicodeMode),\n unicodeMode,\n );\n}\n\n/**\n * The position one attempt actually starts at.\n *\n * The edition converts a string index into an index into the character\n * list it matches over, and under `u` or `v` both code units of a\n * surrogate pair belong to the one character they encode. A start index\n * that splits a pair therefore names that character, not its trailing\n * code unit, so the attempt begins at the pair.\n */\nfunction alignedStart(\n text: string,\n index: number,\n unicodeMode: boolean,\n): number {\n if (!unicodeMode || index <= 0 || index >= text.length) return index;\n const trail = text.charCodeAt(index);\n const lead = text.charCodeAt(index - 1);\n const paired =\n trail >= 0xdc_00 && trail <= 0xdf_ff && lead >= 0xd8_00 && lead <= 0xdb_ff;\n return paired ? index - 1 : index;\n}\n\n/** The four code points the LineTerminator production names. */\nfunction isLineTerminator(character: number): boolean {\n return (\n character === 0x0a ||\n character === 0x0d ||\n character === 0x20_28 ||\n character === 0x20_29\n );\n}\n\n/**\n * The mutable state of one attempt.\n *\n * Every register write is recorded on a trail, so one backtrack entry\n * restores the whole state by truncating the trail to a recorded height\n * rather than by copying the registers. Both stacks are explicit and\n * checked, so a deeply backtracking pattern reports an owned limit instead\n * of consuming a native call stack.\n */\ninterface Machine {\n readonly limits: RegExpExecutionLimits;\n readonly program: RegExpMatcherProgram;\n readonly registers: number[];\n readonly stackIndex: number[];\n readonly stackProgram: number[];\n readonly stackTrail: number[];\n readonly text: string;\n readonly trailRegister: number[];\n readonly trailValue: number[];\n readonly unicodeMode: boolean;\n index: number;\n limit: RegExpExecutionLimit | undefined;\n steps: number;\n}\n\nfunction write(machine: Machine, register: number, value: number): boolean {\n if (machine.trailRegister.length >= machine.limits.trailEntries) {\n machine.limit = \"trail-entries\";\n return false;\n }\n machine.trailRegister.push(register);\n machine.trailValue.push(machine.registers[register] ?? unset);\n machine.registers[register] = value;\n return true;\n}\n\nfunction undoTrail(machine: Machine, height: number): void {\n while (machine.trailRegister.length > height) {\n const register = machine.trailRegister.pop() ?? 0;\n machine.registers[register] = machine.trailValue.pop() ?? unset;\n }\n}\n\nfunction push(machine: Machine, address: number): boolean {\n if (machine.stackProgram.length >= machine.limits.backtrackEntries) {\n machine.limit = \"backtrack-entries\";\n return false;\n }\n machine.stackProgram.push(address);\n machine.stackIndex.push(machine.index);\n machine.stackTrail.push(machine.trailRegister.length);\n return true;\n}\n\n/** The address one backtrack entry resumes at, or -1 when none is left. */\nfunction pop(machine: Machine): number {\n const address = machine.stackProgram.pop();\n if (address == null) return -1;\n machine.index = machine.stackIndex.pop() ?? 0;\n undoTrail(machine, machine.stackTrail.pop() ?? 0);\n return address;\n}\n\n/**\n * The outcome of one backreference, with the steps a lowering charges.\n *\n * A lowering writes one instruction per candidate capture, so `steps` is\n * how many of those a native program executes: every candidate when the\n * reference succeeds, because a capture that did not participate matches\n * the empty string, and only the candidates up to and including the one\n * that failed otherwise. `limited` reports that the step budget ran out\n * before a candidate could run, which is where a lowered program stops.\n * Charging that here is what keeps the artifact's reviewed step limit a\n * bound on the lowered program rather than on this array's length.\n */\ninterface BackreferenceAttempt {\n readonly limited: boolean;\n readonly matched: boolean;\n readonly steps: number;\n}\n\n/**\n * Match one backreference, or report that the path fails.\n *\n * The candidates run one at a time, in the order a lowering writes them,\n * and `allowed` is how many of them the remaining step budget admits, so\n * a request with one step left reads one candidate rather than the whole\n * list. A candidate whose capture did not participate matches the empty\n * string; the edition lets at most one of them participate, and running\n * each in turn is what makes that a consequence rather than an\n * assumption.\n */\nfunction matchBackreference(\n machine: Machine,\n slots: readonly number[],\n backward: boolean,\n ignoreCase: boolean,\n allowed: number,\n): BackreferenceAttempt {\n const total = Math.max(slots.length, 1);\n const table = ignoreCase ? machine.program.canonicalization : undefined;\n for (let candidate = 0; candidate < total; candidate += 1) {\n if (candidate >= allowed) {\n return { limited: true, matched: false, steps: allowed };\n }\n const refused = { limited: false, matched: false, steps: candidate + 1 };\n const slot = slots[candidate];\n if (slot == null) continue;\n const start = machine.registers[slot] ?? unset;\n const end = machine.registers[slot + 1] ?? unset;\n if (start === unset || end === unset) continue;\n const length = end - start;\n const target = backward ? machine.index - length : machine.index;\n if (target < 0 || target + length > machine.text.length) return refused;\n let source = start;\n let compared = target;\n let equal = true;\n while (source < end) {\n const width = widthAt(machine.text, source, machine.unicodeMode);\n const left = characterAt(machine.text, source, machine.unicodeMode);\n const right = characterAt(machine.text, compared, machine.unicodeMode);\n if (canonicalize(table, left) !== canonicalize(table, right)) {\n equal = false;\n break;\n }\n source += width;\n compared += width;\n }\n if (!equal) return refused;\n machine.index = backward ? target : target + length;\n }\n return { limited: false, matched: true, steps: total };\n}\n\nfunction matchesBoundary(machine: Machine, set: RegExpMatcherSet): boolean {\n const before = characterBefore(\n machine.text,\n machine.index,\n machine.unicodeMode,\n );\n const wordBefore = before >= 0 && setHas(set, before);\n const wordAfter =\n machine.index < machine.text.length &&\n setHas(set, characterAt(machine.text, machine.index, machine.unicodeMode));\n return wordBefore !== wordAfter;\n}\n\nfunction matchesEdge(\n machine: Machine,\n assertion: \"end\" | \"start\",\n multiline: boolean,\n): boolean {\n if (assertion === \"start\") {\n if (machine.index === 0) return true;\n if (!multiline) return false;\n return isLineTerminator(\n characterBefore(machine.text, machine.index, machine.unicodeMode),\n );\n }\n if (machine.index === machine.text.length) return true;\n if (!multiline) return false;\n return isLineTerminator(\n characterAt(machine.text, machine.index, machine.unicodeMode),\n );\n}\n\nfunction collectCaptures(\n machine: Machine,\n): readonly (RegExpSpan | undefined)[] {\n const total = machine.program.captures.length + 1;\n const captures: (RegExpSpan | undefined)[] = [];\n for (let index = 0; index < total; index += 1) {\n const start = machine.registers[2 * index] ?? unset;\n const end = machine.registers[2 * index + 1] ?? unset;\n captures.push(\n start === unset || end === unset ? undefined : { end, start },\n );\n }\n return captures;\n}\n\n/**\n * Prove the entire artifact is ^set+$ before touching match state.\n *\n * Keep this exact layout proof in sync with anchored_repeat_set in C.\n * There is no continuation, capture, empty body or alternative whose\n * state could escape the scan. Everything else keeps ordered execution.\n */\nfunction anchoredRepeatSet(\n program: RegExpMatcherProgram,\n): RegExpMatcherSet | undefined {\n if (\n ![\"\", \"u\", \"v\"].includes(program.flags.text) ||\n program.captures.length !== 0 ||\n program.registers !== 4 ||\n program.instructions.length !== 11\n )\n return undefined;\n const [\n save,\n start,\n init,\n repeat,\n enter,\n consume,\n end,\n edge,\n close,\n accept,\n fail,\n ] = program.instructions;\n if (\n save?.kind !== \"save\" ||\n save.slot !== 0 ||\n start?.kind !== \"edge\" ||\n start.assertion !== \"start\" ||\n start.multiline ||\n init?.kind !== \"repeat-init\" ||\n init.counter !== 2 ||\n repeat?.kind !== \"repeat\" ||\n repeat.counter !== 2 ||\n repeat.enter !== 4 ||\n repeat.exit !== 7 ||\n !repeat.greedy ||\n repeat.minimum !== 1 ||\n repeat.maximum !== Infinity ||\n enter?.kind !== \"repeat-enter\" ||\n enter.counter !== 2 ||\n enter.position !== 3 ||\n enter.body !== 5 ||\n enter.clearFrom !== 0 ||\n enter.clearTo !== 0 ||\n consume?.kind !== \"consume\" ||\n consume.backward ||\n end?.kind !== \"repeat-end\" ||\n end.counter !== 2 ||\n end.position !== 3 ||\n end.head !== 3 ||\n end.minimum !== 1 ||\n edge?.kind !== \"edge\" ||\n edge.assertion !== \"end\" ||\n edge.multiline ||\n close?.kind !== \"save\" ||\n close.slot !== 1 ||\n accept?.kind !== \"accept\" ||\n fail?.kind !== \"fail\"\n )\n return undefined;\n return program.sets[consume.set];\n}\n\n/**\n * Constant-state scan of a proved complete pattern, with no undo state.\n * Charge one entry, one per character tested, and one terminal decision.\n * The existing step ceiling remains explicit; no trail or stack is used.\n * Non-multiline $ requires InputLength, including after line terminators.\n */\nfunction scanAnchoredRepeat(\n request: RegExpExecutionInput,\n limits: RegExpExecutionLimits,\n set: RegExpMatcherSet,\n): RegExpExecution {\n const { program, text } = request;\n let steps = 0;\n const limited = (): RegExpLimitedExecution => ({\n limit: \"steps\",\n outcome: \"limit\",\n steps,\n });\n if (steps >= limits.steps) return limited();\n steps += 1;\n if (alignedStart(text, request.startIndex, program.unicodeMode) !== 0) {\n return { outcome: \"unmatched\", steps };\n }\n let index = 0;\n while (index < text.length) {\n if (steps >= limits.steps) return limited();\n steps += 1;\n const character = characterAt(text, index, program.unicodeMode);\n if (!setHas(set, character)) return { outcome: \"unmatched\", steps };\n index += character > 0xff_ff ? 2 : 1;\n }\n if (steps >= limits.steps) return limited();\n steps += 1;\n return index === 0\n ? { outcome: \"unmatched\", steps }\n : {\n captures: [{ end: index, start: 0 }],\n outcome: \"matched\",\n steps,\n };\n}\n\n/**\n * Run one anchored match attempt at one position.\n *\n * The attempt starts at `startIndex` and never searches a later position;\n * `searchRegExpMatcher` owns that loop. Under `u` or `v` a start index\n * that splits a surrogate pair names the character the pair encodes, so\n * the attempt begins at the pair rather than at its trailing code unit.\n */\nexport function matchRegExpMatcher(\n request: RegExpExecutionInput,\n): RegExpExecution {\n const { program, startIndex, text } = request;\n const limits = checkRequest(request);\n if (startIndex < 0 || startIndex > text.length) {\n return { outcome: \"unmatched\", steps: 0 };\n }\n const scanSet = anchoredRepeatSet(program);\n if (scanSet != null) return scanAnchoredRepeat(request, limits, scanSet);\n const machine: Machine = {\n index: alignedStart(text, startIndex, program.unicodeMode),\n limit: undefined,\n limits,\n program,\n registers: Array.from({ length: program.registers }, () => unset),\n stackIndex: [],\n stackProgram: [],\n stackTrail: [],\n steps: 0,\n text,\n trailRegister: [],\n trailValue: [],\n unicodeMode: program.unicodeMode,\n };\n for (\n let index = 2 * (program.captures.length + 1);\n index < program.registers;\n index += 1\n ) {\n machine.registers[index] = 0;\n }\n let address = 0;\n for (;;) {\n if (machine.steps >= limits.steps) {\n return { limit: \"steps\", outcome: \"limit\", steps: machine.steps };\n }\n machine.steps += 1;\n const instruction = program.instructions[address];\n if (instruction == null) {\n return { outcome: \"unmatched\", steps: machine.steps };\n }\n let failed = false;\n if (instruction.kind === \"accept\") {\n return {\n captures: collectCaptures(machine),\n outcome: \"matched\",\n steps: machine.steps,\n };\n } else if (instruction.kind === \"consume\") {\n const width = instruction.backward\n ? widthBefore(text, machine.index, machine.unicodeMode)\n : widthAt(text, machine.index, machine.unicodeMode);\n const at = instruction.backward ? machine.index - width : machine.index;\n const next = instruction.backward ? at : machine.index + width;\n const set = program.sets[instruction.set] ?? [];\n if (\n at < 0 ||\n at >= text.length ||\n next < 0 ||\n next > text.length ||\n !setHas(set, characterAt(text, at, machine.unicodeMode))\n ) {\n failed = true;\n } else {\n machine.index = next;\n address += 1;\n }\n } else if (instruction.kind === \"edge\") {\n if (matchesEdge(machine, instruction.assertion, instruction.multiline)) {\n address += 1;\n } else failed = true;\n } else if (instruction.kind === \"boundary\") {\n const set = program.sets[instruction.set] ?? [];\n if (matchesBoundary(machine, set) !== instruction.negated) address += 1;\n else failed = true;\n } else if (instruction.kind === \"save\") {\n if (!write(machine, instruction.slot, machine.index)) {\n return limitReached(machine);\n }\n address += 1;\n } else if (instruction.kind === \"clear\") {\n for (let slot = instruction.from; slot < instruction.to; slot += 1) {\n if (!write(machine, slot, unset)) return limitReached(machine);\n }\n address += 1;\n } else if (instruction.kind === \"fork\") {\n if (!push(machine, instruction.alternative)) {\n return limitReached(machine);\n }\n address = instruction.preferred;\n } else if (instruction.kind === \"jump\") {\n address = instruction.target;\n } else if (instruction.kind === \"repeat\") {\n const done = machine.registers[instruction.counter] ?? 0;\n if (done < instruction.minimum) address = instruction.enter;\n else if (done >= instruction.maximum) address = instruction.exit;\n else if (instruction.greedy) {\n if (!push(machine, instruction.exit)) return limitReached(machine);\n address = instruction.enter;\n } else {\n if (!push(machine, instruction.enter)) return limitReached(machine);\n address = instruction.exit;\n }\n } else if (instruction.kind === \"repeat-init\") {\n if (!write(machine, instruction.counter, 0)) return limitReached(machine);\n address += 1;\n } else if (instruction.kind === \"repeat-enter\") {\n const done = machine.registers[instruction.counter] ?? 0;\n if (!write(machine, instruction.counter, done + 1)) {\n return limitReached(machine);\n }\n if (!write(machine, instruction.position, machine.index)) {\n return limitReached(machine);\n }\n for (\n let slot = instruction.clearFrom;\n slot < instruction.clearTo;\n slot += 1\n ) {\n if (!write(machine, slot, unset)) return limitReached(machine);\n }\n address = instruction.body;\n } else if (instruction.kind === \"repeat-end\") {\n const done = (machine.registers[instruction.counter] ?? 1) - 1;\n const started = machine.registers[instruction.position] ?? unset;\n if (done >= instruction.minimum && started === machine.index) {\n failed = true;\n } else address = instruction.head;\n } else if (instruction.kind === \"look-start\") {\n if (!push(machine, instruction.onFail)) return limitReached(machine);\n if (!write(machine, instruction.frame, machine.stackProgram.length - 1)) {\n return limitReached(machine);\n }\n address = instruction.body;\n } else if (instruction.kind === \"look-end\") {\n const frame = machine.registers[instruction.frame] ?? 0;\n const entryIndex = machine.stackIndex[frame] ?? 0;\n const entryTrail = machine.stackTrail[frame] ?? 0;\n machine.stackProgram.length = frame;\n machine.stackIndex.length = frame;\n machine.stackTrail.length = frame;\n machine.index = entryIndex;\n if (instruction.negated) {\n undoTrail(machine, entryTrail);\n failed = true;\n } else address = instruction.exit;\n } else if (instruction.kind === \"backreference\") {\n // The loop already charged the first candidate, so the budget is\n // that one plus whatever the step limit still admits.\n const attempt = matchBackreference(\n machine,\n instruction.slots,\n instruction.backward,\n instruction.ignoreCase,\n machine.limits.steps - machine.steps + 1,\n );\n machine.steps += attempt.steps - 1;\n if (attempt.limited) {\n return { limit: \"steps\", outcome: \"limit\", steps: machine.steps };\n }\n if (attempt.matched) address += 1;\n else failed = true;\n } else failed = true;\n if (failed) {\n const resumed = pop(machine);\n if (resumed < 0) return { outcome: \"unmatched\", steps: machine.steps };\n address = resumed;\n }\n }\n}\n\nfunction limitReached(machine: Machine): RegExpLimitedExecution {\n return {\n limit: machine.limit ?? \"steps\",\n outcome: \"limit\",\n steps: machine.steps,\n };\n}\n\n/**\n * Search for the first match at or after one position.\n *\n * This is the position loop of the edition's built-in execution without\n * any object state: a sticky pattern attempts only the given position, and\n * every other pattern advances by one character until the input is\n * exhausted. `lastIndex`, the result array, and `exec` dispatch belong to\n * the unit that adds the `RegExp` intrinsic.\n */\nexport function searchRegExpMatcher(\n request: RegExpExecutionInput,\n): RegExpExecution {\n const { program, text } = request;\n const limits = checkRequest(request);\n let steps = 0;\n if (request.startIndex < 0 || request.startIndex > text.length) {\n return { outcome: \"unmatched\", steps: 0 };\n }\n const scanSet = anchoredRepeatSet(program);\n if (scanSet != null) return scanAnchoredRepeat(request, limits, scanSet);\n let index = alignedStart(text, request.startIndex, program.unicodeMode);\n for (;;) {\n const attempt = matchRegExpMatcher({\n limits: {\n backtrackEntries: limits.backtrackEntries,\n steps: limits.steps - steps,\n trailEntries: limits.trailEntries,\n },\n program,\n startIndex: index,\n text,\n });\n steps += attempt.steps;\n if (attempt.outcome === \"matched\") {\n return { captures: attempt.captures, outcome: \"matched\", steps };\n }\n if (attempt.outcome === \"limit\") {\n return { limit: attempt.limit, outcome: \"limit\", steps };\n }\n if (program.flags.sticky || index >= text.length) {\n return { outcome: \"unmatched\", steps };\n }\n index += widthAt(text, index, program.unicodeMode);\n }\n}\n"],"mappings":";;;;AA+CA,MAAa,+BAAsD;CACjE,kBAAkB;CAClB,OAAO;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B,MAAM,EAAE,SAAS,SAAS;CAC1B,MAAM,SAAS,aAAa,OAAO;CACnC,IAAI,QAAQ;CACZ,IAAI,QAAQ,aAAa,KAAK,QAAQ,aAAa,KAAK,QACtD,OAAO;EAAE,SAAS;EAAa,OAAO;CAAE;CAE1C,MAAM,UAAU,kBAAkB,OAAO;CACzC,IAAI,WAAW,MAAM,OAAO,mBAAmB,SAAS,QAAQ,OAAO;CACvE,IAAI,QAAQ,aAAa,MAAM,QAAQ,YAAY,QAAQ,WAAW;CACtE,SAAS;EACP,MAAM,UAAU,mBAAmB;GACjC,QAAQ;IACN,kBAAkB,OAAO;IACzB,OAAO,OAAO,QAAQ;IACtB,cAAc,OAAO;GACvB;GACA;GACA,YAAY;GACZ;EACF,CAAC;EACD,SAAS,QAAQ;EACjB,IAAI,QAAQ,YAAY,WACtB,OAAO;GAAE,UAAU,QAAQ;GAAU,SAAS;GAAW;EAAM;EAEjE,IAAI,QAAQ,YAAY,SACtB,OAAO;GAAE,OAAO,QAAQ;GAAO,SAAS;GAAS;EAAM;EAEzD,IAAI,QAAQ,MAAM,UAAU,SAAS,KAAK,QACxC,OAAO;GAAE,SAAS;GAAa;EAAM;EAEvC,SAAS,QAAQ,MAAM,OAAO,QAAQ,WAAW;CACnD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexp-matcher.d.ts","names":[],"sources":["../src/regexp-matcher.ts"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"regexp-matcher.d.ts","names":[],"sources":["../src/regexp-matcher.ts"],"mappings":";;;;;;;;;;;;;;;;KAkEY;;;;;;;;;;UAgMK;WACN;WACA;;;UAIM;WACN;WACA;WACA;;;UAIM;WACN;WACA;WACA;;;UAIM;WACN;WACA;WACA;;;UAIM;WACN;WACA;;;UAIM;WACN;WACA;WACA;;;UAIM;WACN;WACA;WACA;;;UAIM;WACN;WACA;;;;;;;;;;UAWM;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;;;;UAUM;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;WACA;WACA;;;;;;;;;UAUM;WACN;WACA;WACA;WACA;WACA;;;;;;;;;;;;UAaM;WACN;WACA;WACA;WACA;WACA;;;;;;;;;UAUM;WACN;WACA;WACA;WACA;;;;;;;;;;UAWM;WACN;WACA;WACA;WACA;;;UAIM;WACN;;;UAIM;WACN;;;KAIC,2BACR,sBACA,6BACA,wBACA,qBACA,uBACA,oBACA,oBACA,oBACA,oBACA,uBACA,yBACA,sBACA,yBACA,2BACA,0BACA;;;;;;;;;;;;;;UAea;WACN,mBAAmB;WACnB,mBAAmB;WACnB,OAAO;WACP;WACA,uBAAuB;WACvB;WACA;WACA,eAAe;WACf;WACA;;;;;;;;;;;;;;;;;UAkBM;WACN,0BACP;WAEO,eACP,QAAQ,gCACL;WACI,qBACP,QAAQ;WAED,wBAAwB;WACxB,kBAAkB;;;;;;;;;;UAWZ;;;;;;WAMN;WACA;;;cAIE,4BAA4B;;UAMxB;WACN,SAAS;WACT,cAAc;;;;;;;;UASR;WACN;WACA,iBAAiB;WACjB,UAAU;;;;;;;;;;iBAWL,wBAAwB,eAAe;;;;;;;;;;iBA4uCvC,mBACd,SAAS,eACT,UAAS,uBACR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexp-matcher.js","names":[],"sources":["../src/regexp-matcher.ts"],"sourcesContent":["import {\n regExpUnicodeMode,\n type RegExpAlternative,\n type RegExpAtom,\n type RegExpCapture,\n type RegExpCharacterClass,\n type RegExpClassSetOperand,\n type RegExpClassEscapeSet,\n type RegExpClassItem,\n type RegExpDisjunction,\n type RegExpEdgeAssertion,\n type RegExpFlags,\n type RegExpLookaround,\n type RegExpPattern,\n type RegExpPatternError,\n type RegExpQuantified,\n type RegExpSpan,\n type RegExpTerm,\n type RegExpUnicodePropertyEscape,\n type RegExpUnicodeClassSet,\n} from \"./regexp.ts\";\n\nfunction includePropertiesWhen<const Properties extends object>(\n properties: () => Properties | undefined,\n): Properties | { [Key in keyof Properties]?: never } {\n return properties() ?? {};\n}\n\n/** The largest Unicode code point. */\nconst maximumCodePoint = 0x10_ffff;\n\n/** One past the largest code point, the only non-code-point boundary. */\nconst codePointLimit = maximumCodePoint + 1;\n\n/**\n * One immutable character set as an inversion list.\n *\n * The list is a strictly increasing, even-length array of boundaries where\n * membership toggles, so `[0x41, 0x5b]` is U+0041 through U+005A. A closing\n * boundary may equal one past the largest code point, which is the only\n * value the list may hold that is not itself a code point.\n *\n * `@oseo/unicode` publishes its tables in exactly this shape, so a table\n * reaches an artifact without being reshaped. The compiler core links no\n * Unicode data, so the few set operations the builder needs are implemented\n * here rather than imported: the dependency direction, not the duplication,\n * is what the package boundary protects.\n */\nexport type RegExpMatcherSet = readonly number[];\n\n/** Whether one inversion list holds one code point. */\nfunction setHas(set: RegExpMatcherSet, codePoint: number): boolean {\n let low = 0;\n let high = set.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n if ((set[middle] ?? 0) <= codePoint) low = middle + 1;\n else high = middle;\n }\n return (low & 1) === 1;\n}\n\n/** One inclusive code-point range as an inversion list. */\nfunction setOfRange(start: number, end: number): RegExpMatcherSet {\n return start > end ? [] : [start, end + 1];\n}\n\n/** The union of two inversion lists. */\nfunction setUnion(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n): RegExpMatcherSet {\n const boundaries: number[] = [];\n let leftIndex = 0;\n let rightIndex = 0;\n let depth = 0;\n while (leftIndex < left.length || rightIndex < right.length) {\n const leftValue = left[leftIndex] ?? codePointLimit + 1;\n const rightValue = right[rightIndex] ?? codePointLimit + 1;\n const value = Math.min(leftValue, rightValue);\n let opening = 0;\n if (leftValue === value) {\n opening += (leftIndex & 1) === 0 ? 1 : -1;\n leftIndex += 1;\n }\n if (rightValue === value) {\n opening += (rightIndex & 1) === 0 ? 1 : -1;\n rightIndex += 1;\n }\n const previous = depth;\n depth += opening;\n if (previous === 0 && depth > 0) boundaries.push(value);\n else if (previous > 0 && depth === 0) boundaries.push(value);\n }\n return boundaries;\n}\n\n/**\n * A running union of inversion lists, held as one partial union per rank.\n *\n * Slot `rank` holds the union of a run of exactly `2 ** rank` lists, so\n * adding one list carries upward the way a binary counter does. Every\n * boundary then takes part in a logarithmic number of merges rather than\n * in one merge for each list that follows it, and the accumulator holds\n * one partial union per rank rather than one per list.\n *\n * Folding `setUnion` from the left instead rewalks the whole accumulated\n * list once per operand, which is the square of the operand count for a\n * union whose operands name distinct code points. Collecting the lists\n * and merging them at the end holds every operand at once, which a union\n * of many large operands cannot afford.\n */\ntype SetUnionSlots = (RegExpMatcherSet | undefined)[];\n\n/** Add one inversion list to a running union. */\nfunction addSetUnion(slots: SetUnionSlots, set: RegExpMatcherSet): void {\n let carry = set;\n for (let rank = 0; ; rank += 1) {\n const held = slots[rank];\n if (held == null) {\n slots[rank] = carry;\n return;\n }\n slots[rank] = undefined;\n carry = setUnion(held, carry);\n }\n}\n\n/** The union every slot of a running union holds together. */\nfunction finishSetUnion(slots: SetUnionSlots): RegExpMatcherSet {\n let union: RegExpMatcherSet = [];\n for (const held of slots) {\n if (held != null) union = setUnion(union, held);\n }\n return union;\n}\n\n/** The complement of one inversion list over the whole code-point range. */\nfunction setComplement(set: RegExpMatcherSet): RegExpMatcherSet {\n const boundaries: number[] = [];\n let position = 0;\n for (let index = 0; index + 1 < set.length; index += 2) {\n const start = set[index] ?? 0;\n if (start > position) boundaries.push(position, start);\n position = set[index + 1] ?? 0;\n }\n if (position < codePointLimit) boundaries.push(position, codePointLimit);\n return boundaries;\n}\n\nfunction combineSets(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n include: (inLeft: boolean, inRight: boolean) => boolean,\n): RegExpMatcherSet {\n const points = [...new Set([0, ...left, ...right, codePointLimit])].toSorted(\n (first, second) => first - second,\n );\n const result: number[] = [];\n let included = false;\n for (let index = 0; index + 1 < points.length; index += 1) {\n const point = points[index] ?? 0;\n const next = include(setHas(left, point), setHas(right, point));\n if (next !== included) result.push(point);\n included = next;\n }\n if (included) result.push(codePointLimit);\n return result;\n}\n\n/** The intersection of two inversion lists. */\nfunction setIntersection(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n): RegExpMatcherSet {\n return combineSets(left, right, (inLeft, inRight) => inLeft && inRight);\n}\n\n/** The members of the first inversion list absent from the second. */\nfunction setDifference(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n): RegExpMatcherSet {\n return combineSets(left, right, (inLeft, inRight) => inLeft && !inRight);\n}\n\n/** Build a normalized inversion list from unsorted inclusive ranges. */\nfunction setOfRanges(\n ranges: readonly (readonly [number, number])[],\n): RegExpMatcherSet {\n const sorted = ranges\n .filter(([start, end]) => start <= end)\n .toSorted((first, second) => first[0] - second[0]);\n const boundaries: number[] = [];\n for (const [start, end] of sorted) {\n const last = boundaries.length - 1;\n const previousEnd = boundaries[last];\n if (previousEnd != null && start <= previousEnd) {\n if (end + 1 > previousEnd) boundaries[last] = end + 1;\n continue;\n }\n boundaries.push(start, end + 1);\n }\n return boundaries;\n}\n\n/** The four code points the LineTerminator production names. */\nconst lineTerminators: RegExpMatcherSet = setOfRanges([\n [0x0a, 0x0a],\n [0x0d, 0x0d],\n [0x20_28, 0x20_29],\n]);\n\n/** The sixty-three characters `WordCharacters` calls basic. */\nconst basicWordCharacters: RegExpMatcherSet = setOfRanges([\n [0x30, 0x39],\n [0x41, 0x5a],\n [0x5f, 0x5f],\n [0x61, 0x7a],\n]);\n\n/** The decimal digits `\\d` names. */\nconst decimalDigits: RegExpMatcherSet = setOfRange(0x30, 0x39);\n\n/** The whitespace `\\s` names apart from `General_Category=Space_Separator`. */\nconst namedWhiteSpace: RegExpMatcherSet = setOfRanges([\n [0x09, 0x09],\n [0x0b, 0x0c],\n [0xfe_ff, 0xfe_ff],\n]);\n\n/**\n * One code point that canonicalizes to another, recorded for execution.\n *\n * `characters` is strictly increasing and `canonical` holds the canonical\n * form of the character at the same offset. A character the table omits\n * canonicalizes to itself. The executor needs this only where a\n * backreference compares two input characters under `i`; every other\n * ignore-case decision is folded into a set while the artifact is built.\n */\nexport interface RegExpMatcherCanonicalization {\n readonly canonical: readonly number[];\n readonly characters: readonly number[];\n}\n\n/** Consume one character of the input in the instruction's direction. */\nexport interface RegExpMatcherConsume {\n readonly backward: boolean;\n readonly kind: \"consume\";\n readonly set: number;\n}\n\n/** Assert `^` or `$` at the current position. */\nexport interface RegExpMatcherEdge {\n readonly assertion: \"end\" | \"start\";\n readonly kind: \"edge\";\n readonly multiline: boolean;\n}\n\n/** Assert `\\b` or `\\B` at the current position. */\nexport interface RegExpMatcherBoundary {\n readonly kind: \"boundary\";\n readonly negated: boolean;\n readonly set: number;\n}\n\n/** Record the current position in one capture register. */\nexport interface RegExpMatcherSave {\n readonly kind: \"save\";\n readonly slot: number;\n}\n\n/** Reset a contiguous capture register range to unset. */\nexport interface RegExpMatcherClear {\n readonly from: number;\n readonly kind: \"clear\";\n readonly to: number;\n}\n\n/** Try one continuation first and keep the other for backtracking. */\nexport interface RegExpMatcherFork {\n readonly alternative: number;\n readonly kind: \"fork\";\n readonly preferred: number;\n}\n\n/** Continue at one address. */\nexport interface RegExpMatcherJump {\n readonly kind: \"jump\";\n readonly target: number;\n}\n\n/**\n * Decide whether one repetition iterates again.\n *\n * Below `minimum` the iteration is forced, at `maximum` the repetition\n * exits, and between them `greedy` orders the two continuations. The\n * decision never inspects the input, so a repetition is one loop in the\n * artifact whatever its bounds say.\n */\nexport interface RegExpMatcherRepeat {\n readonly counter: number;\n readonly enter: number;\n readonly exit: number;\n readonly greedy: boolean;\n readonly kind: \"repeat\";\n readonly maximum: number;\n readonly minimum: number;\n}\n\n/**\n * Begin one repetition, discarding the count of any earlier entry.\n *\n * The edition gives every entry into a quantified atom a fresh repetition\n * state, so a repetition nested in another one starts over each time the\n * outer body runs rather than resuming the count it left behind.\n */\nexport interface RegExpMatcherRepeatInit {\n readonly counter: number;\n readonly kind: \"repeat-init\";\n}\n\n/** Start one repetition iteration, clearing the captures it may set. */\nexport interface RegExpMatcherRepeatEnter {\n readonly body: number;\n readonly clearFrom: number;\n readonly clearTo: number;\n readonly counter: number;\n readonly kind: \"repeat-enter\";\n readonly position: number;\n}\n\n/**\n * Finish one repetition iteration.\n *\n * An iteration that consumed nothing fails once the repetition has met its\n * lower bound, which is what stops an empty body from repeating forever\n * while still letting the bound itself be satisfied by empty iterations.\n */\nexport interface RegExpMatcherRepeatEnd {\n readonly counter: number;\n readonly head: number;\n readonly kind: \"repeat-end\";\n readonly minimum: number;\n readonly position: number;\n}\n\n/**\n * Enter one lookaround body.\n *\n * The instruction records the backtrack height its body may not unwind\n * past, so the body's own choices are discarded when it finishes.\n * `onFail` is where the assertion continues once its body has no match\n * left: the shared failure instruction for a positive assertion, and the\n * instruction after the assertion for a negative one, which is the only\n * way a negative assertion succeeds.\n */\nexport interface RegExpMatcherLookStart {\n readonly body: number;\n readonly frame: number;\n readonly kind: \"look-start\";\n readonly negated: boolean;\n readonly onFail: number;\n}\n\n/**\n * Leave one lookaround body that matched.\n *\n * A positive assertion restores the entry position, keeps the captures the\n * body set, and discards the body's remaining choices. A negative\n * assertion undoes both and fails.\n */\nexport interface RegExpMatcherLookEnd {\n readonly exit: number;\n readonly frame: number;\n readonly kind: \"look-end\";\n readonly negated: boolean;\n}\n\n/**\n * Match the text one earlier capture holds.\n *\n * `slots` names every capture a group name resolves to, in ascending\n * index order. At most one of them can have participated in the match, and\n * a reference to a capture that did not participate matches the empty\n * string rather than failing.\n */\nexport interface RegExpMatcherBackreference {\n readonly backward: boolean;\n readonly ignoreCase: boolean;\n readonly kind: \"backreference\";\n readonly slots: readonly number[];\n}\n\n/** Report the whole pattern as matched. */\nexport interface RegExpMatcherAccept {\n readonly kind: \"accept\";\n}\n\n/** Abandon the current path and backtrack. */\nexport interface RegExpMatcherFail {\n readonly kind: \"fail\";\n}\n\n/** One instruction of a matcher artifact. */\nexport type RegExpMatcherInstruction =\n | RegExpMatcherAccept\n | RegExpMatcherBackreference\n | RegExpMatcherBoundary\n | RegExpMatcherClear\n | RegExpMatcherConsume\n | RegExpMatcherEdge\n | RegExpMatcherFail\n | RegExpMatcherFork\n | RegExpMatcherJump\n | RegExpMatcherLookEnd\n | RegExpMatcherLookStart\n | RegExpMatcherRepeat\n | RegExpMatcherRepeatEnd\n | RegExpMatcherRepeatEnter\n | RegExpMatcherRepeatInit\n | RegExpMatcherSave;\n\n/**\n * One immutable matcher artifact.\n *\n * The artifact is the semantic authority for one pattern: an ahead-of-time\n * lowering and any later fast path must produce the match state this\n * program produces. It holds no mutable field and no reference to a\n * regular expression object, so equal artifacts may be shared while every\n * evaluation still owns its own object identity and `lastIndex`.\n *\n * Register 0 and 1 hold the whole match, and registers `2 * index` and\n * `2 * index + 1` hold capturing group `index`. The remaining registers\n * are repetition counters, repetition positions, and lookaround frames.\n */\nexport interface RegExpMatcherProgram {\n readonly canonicalization?: RegExpMatcherCanonicalization;\n readonly captures: readonly RegExpCapture[];\n readonly flags: RegExpFlags;\n readonly groupNames: readonly string[];\n readonly instructions: readonly RegExpMatcherInstruction[];\n readonly kind: \"matcher\";\n readonly registers: number;\n readonly sets: readonly RegExpMatcherSet[];\n readonly source: string;\n readonly unicodeMode: boolean;\n}\n\n/**\n * Unicode facts the builder cannot derive on its own.\n *\n * The compiler core links no Unicode data, so a caller that owns the\n * pinned tables supplies the raw facts and the builder owns every\n * ECMAScript decision made from them. A pattern whose grammar needs a fact\n * the caller did not supply is refused with a located error rather than\n * matched against a guess.\n *\n * `caseEquivalenceClasses` returns every class of two or more characters\n * that `Canonicalize` maps together for the given mode, which is simple\n * case folding under `u` or `v` and the single-code-unit uppercase rule\n * otherwise. Classes of one character are omitted because they change\n * nothing.\n */\nexport interface RegExpMatcherUnicodeData {\n readonly caseEquivalenceClasses?: (\n unicodeMode: boolean,\n ) => readonly (readonly number[])[];\n readonly propertySet?: (\n escape: RegExpUnicodePropertyEscape,\n ) => RegExpMatcherSet | undefined;\n readonly stringPropertySet?: (\n escape: RegExpUnicodePropertyEscape,\n ) => readonly (readonly number[])[] | undefined;\n readonly generalCategoryValue?: (name: string) => boolean;\n readonly spaceSeparators?: RegExpMatcherSet;\n}\n\n/**\n * Owned boundaries applied while one artifact is built.\n *\n * A pattern the parser already accepted stays within these for any\n * ordinary source, so reaching one reports a located `limit` error rather\n * than producing an artifact whose storage a later native lowering could\n * not describe.\n */\nexport interface RegExpMatcherLimits {\n /**\n * The lowered instruction count, which charges a backreference to a\n * duplicated group name once per candidate capture because that is\n * what a native encoding writes for it.\n */\n readonly instructions: number;\n readonly registers: number;\n}\n\n/** The reviewed default artifact limits. */\nexport const defaultRegExpMatcherLimits: RegExpMatcherLimits = {\n instructions: 0x10_0000,\n registers: 0x4_0000,\n};\n\n/** Optional components of one artifact build. */\nexport interface RegExpMatcherOptions {\n readonly limits?: RegExpMatcherLimits;\n readonly unicodeData?: RegExpMatcherUnicodeData;\n}\n\n/**\n * The outcome of one build.\n *\n * `program` is present exactly when `built` is true, and `errors` is\n * nonempty exactly when it is false.\n */\nexport interface RegExpMatcherResult {\n readonly built: boolean;\n readonly errors: readonly RegExpPatternError[];\n readonly program?: RegExpMatcherProgram;\n}\n\n/**\n * Reject a boundary a caller supplied that is not a count.\n *\n * A limit that is not a nonnegative safe integer would silently disable\n * the boundary it names, because every comparison against it is false.\n * That is a caller defect rather than a pattern the unit cannot describe,\n * so it throws instead of reporting a located pattern error.\n */\nexport function checkRegExpMatcherBound(value: number, subject: string): void {\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new RangeError(`${subject} must be a nonnegative safe integer.`);\n }\n}\n\n/** One rejected construct, thrown so a deep production keeps its span. */\nclass MatcherFailure extends Error {\n readonly error: RegExpPatternError;\n\n constructor(error: RegExpPatternError) {\n super(error.message);\n this.error = error;\n }\n}\n\nfunction refuse(\n kind: \"limit\" | \"unsupported\",\n message: string,\n span: RegExpSpan,\n): never {\n throw new MatcherFailure({ kind, message, section: \"pattern\", span });\n}\n\n/** The address a label holds until it is placed. */\nconst unplacedLabel = -1;\n\n/**\n * The emitter state of one build.\n *\n * A target field holds a label while instructions are emitted and the\n * address the label was placed at afterwards, so a forward branch never\n * needs a mutable instruction.\n */\ninterface Builder {\n readonly addresses: number[];\n readonly failLabel: number;\n readonly instructions: RegExpMatcherInstruction[];\n readonly limits: RegExpMatcherLimits;\n readonly setIndices: Map<string, number>;\n readonly sets: RegExpMatcherSet[];\n readonly unicodeData: RegExpMatcherUnicodeData;\n readonly unicodeMode: boolean;\n readonly unicodeSets: boolean;\n caseRepresentatives: ReadonlyMap<number, number> | undefined;\n classes: readonly (readonly number[])[] | undefined;\n dotAll: boolean;\n ignoreCase: boolean;\n /**\n * How many instructions a native encoding of this artifact needs.\n *\n * Every instruction is one except a backreference to a duplicated group\n * name, which a lowering writes as one instruction per candidate\n * capture because at most one of them can have participated. Charging\n * that expansion here is what keeps the reviewed instruction limit a\n * bound on the storage a later native lowering has to describe rather\n * than on this array's length alone.\n */\n lowered: number;\n multiline: boolean;\n registers: number;\n readonly wordSets: Map<boolean, number>;\n}\n\nfunction newLabel(builder: Builder): number {\n builder.addresses.push(unplacedLabel);\n return builder.addresses.length - 1;\n}\n\nfunction placeLabel(builder: Builder, label: number): void {\n builder.addresses[label] = builder.instructions.length;\n}\n\nfunction emit(\n builder: Builder,\n instruction: RegExpMatcherInstruction,\n span: RegExpSpan,\n): void {\n const cost =\n instruction.kind === \"backreference\"\n ? Math.max(instruction.slots.length, 1)\n : 1;\n if (builder.lowered + cost > builder.limits.instructions) {\n refuse(\n \"limit\",\n \"A pattern needs more matcher instructions than the reviewed limit.\",\n span,\n );\n }\n builder.lowered += cost;\n builder.instructions.push(instruction);\n}\n\nfunction allocateRegisters(\n builder: Builder,\n count: number,\n span: RegExpSpan,\n): number {\n if (builder.registers + count > builder.limits.registers) {\n refuse(\n \"limit\",\n \"A pattern needs more matcher registers than the reviewed limit.\",\n span,\n );\n }\n const base = builder.registers;\n builder.registers += count;\n return base;\n}\n\n/**\n * Intern one set, so equal sets share one artifact entry.\n *\n * The stored list is a frozen copy. A set may have arrived from the\n * caller's Unicode tables, and an artifact must neither freeze a table the\n * caller still owns nor keep a list the caller could rewrite later.\n */\nfunction internSet(builder: Builder, set: RegExpMatcherSet): number {\n const key = set.join(\",\");\n const existing = builder.setIndices.get(key);\n if (existing != null) return existing;\n const index = builder.sets.length;\n builder.sets.push(Object.freeze([...set]));\n builder.setIndices.set(key, index);\n return index;\n}\n\nfunction caseClasses(\n builder: Builder,\n span: RegExpSpan,\n): readonly (readonly number[])[] {\n const cached = builder.classes;\n if (cached != null) return cached;\n const provide = builder.unicodeData.caseEquivalenceClasses;\n if (provide == null) {\n refuse(\n \"unsupported\",\n \"An ignore-case pattern needs case folding data that is not linked.\",\n span,\n );\n }\n const classes = provide(builder.unicodeMode);\n builder.classes = classes;\n return classes;\n}\n\n/**\n * Close one set under the pattern's canonicalization.\n *\n * `CharacterSetMatcher` compares the canonical form of the input character\n * with the canonical form of every set member, so a set matches exactly\n * the characters whose equivalence class meets it. Only a character with a\n * case sibling can join a set it was not already in, so closing walks the\n * equivalence classes rather than the whole code-point range.\n */\nfunction closeSet(\n builder: Builder,\n set: RegExpMatcherSet,\n span: RegExpSpan,\n): RegExpMatcherSet {\n if (!builder.ignoreCase) return set;\n const added: (readonly [number, number])[] = [];\n for (const members of caseClasses(builder, span)) {\n if (!members.some((member) => setHas(set, member))) continue;\n for (const member of members) {\n if (!setHas(set, member)) added.push([member, member]);\n }\n }\n return added.length === 0 ? set : setUnion(set, setOfRanges(added));\n}\n\n/** Map each cased character to one stable representative of its class. */\nfunction caseRepresentatives(\n builder: Builder,\n span: RegExpSpan,\n): ReadonlyMap<number, number> {\n const cached = builder.caseRepresentatives;\n if (cached != null) return cached;\n const representatives = new Map<number, number>();\n for (const members of caseClasses(builder, span)) {\n const representative = members.reduce(\n (lowest, member) => Math.min(lowest, member),\n members[0] ?? 0,\n );\n for (const member of members) representatives.set(member, representative);\n }\n builder.caseRepresentatives = representatives;\n return representatives;\n}\n\n/**\n * The `WordCharacters` of this pattern.\n *\n * The edition adds a character outside the basic sixty-three only when\n * both `i` and a unicode-mode flag are set, and closing the basic set\n * under the non-unicode case rule adds nothing, so one expression covers\n * every flag combination.\n */\nfunction wordCharacters(builder: Builder, span: RegExpSpan): RegExpMatcherSet {\n return closeSet(builder, basicWordCharacters, span);\n}\n\nfunction spaceCharacters(builder: Builder, span: RegExpSpan): RegExpMatcherSet {\n const separators = builder.unicodeData.spaceSeparators;\n if (separators == null) {\n refuse(\n \"unsupported\",\n \"A whitespace class escape needs Unicode category data that is not \" +\n \"linked.\",\n span,\n );\n }\n return setUnion(setUnion(namedWhiteSpace, separators), lineTerminators);\n}\n\n/** The raw set one `\\d`, `\\s`, or `\\w` escape names, before closing. */\nfunction classEscapeSet(\n builder: Builder,\n set: RegExpClassEscapeSet,\n span: RegExpSpan,\n): RegExpMatcherSet {\n if (set === \"digit\") return decimalDigits;\n if (set === \"space\") return spaceCharacters(builder, span);\n return wordCharacters(builder, span);\n}\n\nfunction propertyEscapeSet(\n builder: Builder,\n escape: RegExpUnicodePropertyEscape,\n): RegExpMatcherSet {\n const resolve = builder.unicodeData.propertySet;\n if (resolve == null) {\n refuse(\n \"unsupported\",\n \"A Unicode property escape needs property data that is not linked.\",\n escape.span,\n );\n }\n const resolved = resolve(escape);\n if (resolved == null) {\n refuse(\n \"unsupported\",\n \"This Unicode property names no code-point set.\",\n escape.span,\n );\n }\n if (!escape.negated) return resolved;\n /*\n * The two unicode-mode flags complement a property differently. `v`\n * folds the property first and complements it over the folded code\n * points, so `\\P{Ll}` under `iv` excludes every character equivalent to\n * a lowercase letter. `u` complements the unfolded property instead and\n * lets `CharacterSetMatcher` close the result afterwards, so the same\n * escape under `iu` accepts them. Closing a complemented closed set adds\n * nothing, so the outer closing stays a no-op here.\n */\n if (builder.unicodeSets && builder.ignoreCase) {\n return setComplement(closeSet(builder, resolved, escape.span));\n }\n return setComplement(resolved);\n}\n\ninterface ClassValue {\n readonly characters: RegExpMatcherSet;\n readonly strings: readonly (readonly number[])[];\n}\n\n/** The key two class strings share exactly when they hold the same run. */\nfunction classStringKey(sequence: readonly number[]): string {\n return sequence.join(\",\");\n}\n\n/**\n * Fold one class-set value into a running union of values.\n *\n * The edition holds a one-character `\\q{...}` alternative as a code point\n * rather than as a string, and holds each remaining alternative once. An\n * alternative already in `unique` is left as it was written, so a repeated\n * alternative keeps the spelling and the position of its first appearance,\n * which is the order the class string trie is then built in.\n *\n * `slots` and `unique` are the accumulator: folding is written this way so\n * that a union of many operands folds each operand a bounded number of\n * times and releases it, rather than refolding everything it already\n * holds once more for every operand that follows.\n */\nfunction addClassValue(\n slots: SetUnionSlots,\n unique: Map<string, readonly number[]>,\n value: ClassValue,\n): void {\n const single: (readonly [number, number])[] = [];\n for (const sequence of value.strings) {\n const character = sequence.length === 1 ? sequence[0] : undefined;\n if (character == null) {\n const key = classStringKey(sequence);\n if (!unique.has(key)) unique.set(key, sequence);\n continue;\n }\n single.push([character, character]);\n }\n addSetUnion(slots, value.characters);\n if (single.length > 0) addSetUnion(slots, setOfRanges(single));\n}\n\n/** One class-set value with its one-character alternatives folded in. */\nfunction normalizeClassValue(value: ClassValue): ClassValue {\n const slots: SetUnionSlots = [];\n const unique = new Map<string, readonly number[]>();\n addClassValue(slots, unique, value);\n return {\n characters: finishSetUnion(slots),\n strings: [...unique.values()],\n };\n}\n\nfunction propertyEscapeClassValue(\n builder: Builder,\n escape: RegExpUnicodePropertyEscape,\n): ClassValue {\n const characters = builder.unicodeData.propertySet?.(escape);\n if (characters != null) {\n return { characters: propertyEscapeSet(builder, escape), strings: [] };\n }\n const strings = builder.unicodeData.stringPropertySet?.(escape);\n if (strings == null || escape.negated) {\n refuse(\n \"unsupported\",\n \"A Unicode property of strings needs data that is not linked.\",\n escape.span,\n );\n }\n return normalizeClassValue({ characters: [], strings });\n}\n\n/**\n * Whether one escape is a lone General_Category value such as `\\p{Ll}`.\n *\n * `CompileToCharSet` returns that spelling without folding it, while the\n * `\\p{gc=Ll}` spelling and every binary property end in\n * `MaybeSimpleCaseFolding`. The asymmetry is deliberate and is only\n * observable inside `v`-mode set algebra, where folding an operand before\n * the operation removes members the edition keeps.\n *\n * The builder asks the question the edition asks, whether the name is a\n * General_Category value, through the caller's own data. Holding a table of\n * category names here would put Unicode knowledge in the compiler core,\n * which the package boundary does not allow.\n *\n * The caller answers it directly rather than the builder inferring it from\n * whether some other spelling resolves. A provider that resolves a lone\n * escape but not the classification would otherwise fold an operand the\n * edition keeps exact and match nothing, silently, where every other\n * missing Unicode fact reports an owned refusal.\n */\nfunction loneGeneralCategory(\n builder: Builder,\n escape: RegExpUnicodePropertyEscape,\n): boolean {\n if (escape.value != null) return false;\n const classify = builder.unicodeData.generalCategoryValue;\n if (classify == null) {\n refuse(\n \"unsupported\",\n \"A lone Unicode property escape needs the General_Category value \" +\n \"classification that is not linked.\",\n escape.span,\n );\n }\n return classify(escape.property);\n}\n\n/**\n * Whether one operand keeps its exact code points through set algebra.\n *\n * The edition folds a `ClassSetCharacter` and a `ClassStringDisjunction`\n * operand but returns a `NestedClass` operand unchanged, so a nested class\n * carries whatever its own operands decided rather than being folded again.\n * Closing a nested value that is already closed changes nothing, so this\n * only matters for the one leaf the edition leaves raw.\n */\nfunction preservesExactOperand(\n builder: Builder,\n operand: RegExpClassSetOperand,\n): boolean {\n if (operand.kind === \"class-set\") return true;\n return (\n operand.kind === \"unicode-property\" &&\n !operand.negated &&\n loneGeneralCategory(builder, operand)\n );\n}\n\nfunction classSetOperandValue(\n builder: Builder,\n operand: RegExpClassSetOperand,\n): ClassValue {\n let value: ClassValue;\n if (operand.kind === \"class-set\") {\n value = classSetValue(builder, operand);\n } else if (operand.kind === \"class-strings\") {\n value = normalizeClassValue({\n characters: [],\n strings: operand.strings.map((characters) =>\n characters.map((character) => character.value),\n ),\n });\n } else if (operand.kind === \"unicode-property\") {\n value = propertyEscapeClassValue(builder, operand);\n } else {\n value = { characters: classItemSet(builder, operand), strings: [] };\n }\n if (!builder.unicodeSets || !builder.ignoreCase) return value;\n const representatives = caseRepresentatives(builder, operand.span);\n const exact = preservesExactOperand(builder, operand);\n return normalizeClassValue({\n characters: exact\n ? value.characters\n : closeSet(builder, value.characters, operand.span),\n strings: value.strings.map((sequence) =>\n sequence.map((character) => representatives.get(character) ?? character),\n ),\n });\n}\n\n/** The first operand's value, or the empty value for no operand at all. */\nfunction leadingClassValue(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const first = operands[0];\n if (first == null) return { characters: [], strings: [] };\n return normalizeClassValue(classSetOperandValue(builder, first));\n}\n\n/**\n * The union of every operand, accumulated as the operands resolve.\n *\n * Unioning two values at a time renormalized every alternative the\n * accumulator already held, once per operand, which is the square of the\n * operand count: an admitted one-mebibyte source can write more than a\n * hundred thousand `\\q{...}` operands into one union. Each operand is\n * folded on its own instead, and the alternatives accumulate in a map\n * keyed the way `normalizeClassValue` keys them, so a repeated alternative\n * still keeps the position and spelling of its first appearance and the\n * result is the value the pairwise fold produced.\n *\n * One operand is resolved at a time and released once it has been folded\n * in, because a union of many operands that each name thousands of\n * alternatives cannot hold every operand's value at once.\n */\nfunction unionClassSet(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const slots: SetUnionSlots = [];\n const unique = new Map<string, readonly number[]>();\n for (const operand of operands) {\n addClassValue(slots, unique, classSetOperandValue(builder, operand));\n }\n return {\n characters: finishSetUnion(slots),\n strings: [...unique.values()],\n };\n}\n\n/**\n * The intersection of the first operand with every operand after it.\n *\n * An alternative of the first operand survives exactly when every later\n * operand also holds it, which one counting pass decides. Re-filtering the\n * survivors against each operand in turn would instead cost the first\n * operand's size once per operand. Only an alternative the first operand\n * wrote is counted, so the counts stay within its size however many\n * operands follow.\n */\nfunction intersectClassSet(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const left = leadingClassValue(builder, operands);\n const candidates = new Set(left.strings.map(classStringKey));\n const holders = new Map<string, number>();\n let characters = left.characters;\n let rights = 0;\n for (const [index, operand] of operands.entries()) {\n if (index === 0) continue;\n const value = classSetOperandValue(builder, operand);\n characters = setIntersection(characters, value.characters);\n for (const key of new Set(value.strings.map(classStringKey))) {\n if (!candidates.has(key)) continue;\n holders.set(key, (holders.get(key) ?? 0) + 1);\n }\n rights += 1;\n }\n return {\n characters,\n strings: left.strings.filter(\n (value) => (holders.get(classStringKey(value)) ?? 0) === rights,\n ),\n };\n}\n\n/**\n * The first operand less every operand after it.\n *\n * Difference is left-associative, and removing the operands in turn\n * removes exactly what removing their union removes, so an alternative\n * leaves the survivors the first time a later operand writes it rather\n * than being looked for again in every operand, which would cost the first\n * operand's size once per operand. Only what the first operand wrote is\n * tracked, so the survivors stay within its size however many alternatives\n * the later operands name, and each of their values is released once it\n * has been folded in.\n */\nfunction subtractClassSet(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const left = leadingClassValue(builder, operands);\n const slots: SetUnionSlots = [];\n const surviving = new Set(left.strings.map(classStringKey));\n for (const [index, operand] of operands.entries()) {\n if (index === 0) continue;\n const value = classSetOperandValue(builder, operand);\n addSetUnion(slots, value.characters);\n for (const sequence of value.strings) {\n surviving.delete(classStringKey(sequence));\n }\n }\n return {\n characters: setDifference(left.characters, finishSetUnion(slots)),\n strings: left.strings.filter((value) =>\n surviving.has(classStringKey(value)),\n ),\n };\n}\n\nfunction classSetValue(\n builder: Builder,\n node: RegExpUnicodeClassSet,\n): ClassValue {\n let value: ClassValue;\n if (node.operation === \"union\") {\n value = unionClassSet(builder, node.operands);\n } else if (node.operation === \"intersection\") {\n value = intersectClassSet(builder, node.operands);\n } else {\n value = subtractClassSet(builder, node.operands);\n }\n if (!node.negated) return value;\n if (value.strings.length > 0) {\n refuse(\n \"unsupported\",\n \"A negated class set cannot contain strings.\",\n node.span,\n );\n }\n /*\n * `CharacterComplement` complements over the folded code points under\n * `iv`, so a set that reached here holding the exact members of a lone\n * category is closed first. Complementing it raw would keep every case\n * sibling of its members, which is the opposite of what negation means\n * here. A set that is already closed is unchanged by this.\n */\n const complemented =\n builder.unicodeSets && builder.ignoreCase\n ? closeSet(builder, value.characters, node.span)\n : value.characters;\n return { characters: setComplement(complemented), strings: [] };\n}\n\n/** The raw set one class member names, before the class is closed. */\nfunction classItemSet(\n builder: Builder,\n item: RegExpClassItem,\n): RegExpMatcherSet {\n if (item.kind === \"character\") return setOfRange(item.value, item.value);\n if (item.kind === \"range\") {\n return setOfRange(item.start.value, item.end.value);\n }\n if (item.kind === \"class-escape\") {\n const named = classEscapeSet(builder, item.set, item.span);\n return item.negated ? setComplement(named) : named;\n }\n return propertyEscapeSet(builder, item);\n}\n\nfunction characterClassSet(\n builder: Builder,\n node: RegExpCharacterClass,\n): RegExpMatcherSet {\n let union: RegExpMatcherSet = [];\n for (const item of node.items) {\n union = setUnion(union, classItemSet(builder, item));\n }\n return union;\n}\n\n/**\n * The set one consuming atom matches, or undefined for another atom.\n *\n * Closing comes before negation because `CharacterSetMatcher` inverts a\n * class after canonicalizing its members: `[^a]` under `i` rejects `A`,\n * while closing the complement instead would accept it.\n */\nfunction characterAtomSet(\n builder: Builder,\n atom: RegExpAtom,\n): RegExpMatcherSet | undefined {\n if (atom.kind === \"character\") {\n return closeSet(builder, setOfRange(atom.value, atom.value), atom.span);\n }\n if (atom.kind === \"dot\") {\n const dot = builder.dotAll\n ? setOfRange(0, maximumCodePoint)\n : setComplement(lineTerminators);\n return closeSet(builder, dot, atom.span);\n }\n if (atom.kind === \"class-escape\") {\n const named = classEscapeSet(builder, atom.set, atom.span);\n return closeSet(\n builder,\n atom.negated ? setComplement(named) : named,\n atom.span,\n );\n }\n if (atom.kind === \"unicode-property\") {\n if (\n builder.unicodeData.propertySet?.(atom) == null &&\n builder.unicodeData.stringPropertySet?.(atom) != null\n ) {\n return undefined;\n }\n return closeSet(builder, propertyEscapeSet(builder, atom), atom.span);\n }\n if (atom.kind === \"class-set\") return undefined;\n if (atom.kind !== \"character-class\") return undefined;\n const closed = closeSet(builder, characterClassSet(builder, atom), atom.span);\n return atom.negated ? setComplement(closed) : closed;\n}\n\nfunction emitClassValueBranch(\n builder: Builder,\n sequence: readonly number[] | RegExpMatcherSet,\n characters: boolean,\n backward: boolean,\n span: RegExpSpan,\n): void {\n if (characters) {\n const closed = closeSet(builder, sequence, span);\n emit(\n builder,\n { backward, kind: \"consume\", set: internSet(builder, closed) },\n span,\n );\n return;\n }\n const ordered = backward ? sequence.toReversed() : sequence;\n for (const character of ordered) {\n const closed = closeSet(builder, setOfRange(character, character), span);\n emit(\n builder,\n { backward, kind: \"consume\", set: internSet(builder, closed) },\n span,\n );\n }\n}\n\ninterface ClassStringTrie {\n readonly children: Map<number, ClassStringTrie>;\n terminal: boolean;\n}\n\nfunction classStringTrie(\n sequences: readonly (readonly number[])[],\n backward: boolean,\n): ClassStringTrie {\n const root: ClassStringTrie = { children: new Map(), terminal: false };\n for (const source of sequences.toSorted(\n (first, second) => second.length - first.length,\n )) {\n const sequence = backward ? source.toReversed() : source;\n let node = root;\n for (const character of sequence) {\n const child: ClassStringTrie = node.children.get(character) ?? {\n children: new Map(),\n terminal: false,\n };\n node.children.set(character, child);\n node = child;\n }\n node.terminal = true;\n }\n return root;\n}\n\nfunction emitClassAlternatives(\n builder: Builder,\n branches: readonly (() => void)[],\n span: RegExpSpan,\n): void {\n if (branches.length === 0) return;\n const end = newLabel(builder);\n for (const [index, branch] of branches.entries()) {\n if (index + 1 === branches.length) {\n branch();\n break;\n }\n const preferred = newLabel(builder);\n const next = newLabel(builder);\n emit(builder, { alternative: next, kind: \"fork\", preferred }, span);\n placeLabel(builder, preferred);\n branch();\n emit(builder, { kind: \"jump\", target: end }, span);\n placeLabel(builder, next);\n }\n placeLabel(builder, end);\n}\n\n/**\n * One pending step of the iterative class-string trie emission.\n *\n * A trie is as deep as its longest string, so emitting it through host\n * recursion would spend one frame per code point and exhaust the stack on a\n * `\\q{...}` alternative that the reviewed source and instruction limits both\n * admit. These steps carry that work on the heap instead, and the emitter\n * pops them in the order the equivalent recursion ran, so one pattern still\n * compiles to exactly the same instructions and labels.\n */\ntype ClassStringStep =\n | {\n readonly end: number;\n readonly entries: readonly (readonly [number, ClassStringTrie])[];\n readonly index: number;\n readonly kind: \"branch\";\n readonly terminal: boolean;\n }\n | { readonly character: number; readonly kind: \"consume\" }\n | {\n readonly jump: number | undefined;\n readonly kind: \"finish\";\n readonly label: number;\n }\n | { readonly kind: \"node\"; readonly node: ClassStringTrie };\n\nfunction emitClassStringTrie(\n builder: Builder,\n root: ClassStringTrie,\n backward: boolean,\n span: RegExpSpan,\n): void {\n const steps: ClassStringStep[] = [{ kind: \"node\", node: root }];\n for (;;) {\n const step = steps.pop();\n if (step == null) return;\n if (step.kind === \"consume\") {\n emitClassValueBranch(builder, [step.character], false, backward, span);\n continue;\n }\n if (step.kind === \"finish\") {\n if (step.jump != null) {\n emit(builder, { kind: \"jump\", target: step.jump }, span);\n }\n placeLabel(builder, step.label);\n continue;\n }\n if (step.kind === \"node\") {\n const entries = [...step.node.children];\n const terminal = step.node.terminal;\n if (entries.length === 0 && !terminal) continue;\n steps.push({\n end: newLabel(builder),\n entries,\n index: 0,\n kind: \"branch\",\n terminal,\n });\n continue;\n }\n const { end, entries, index, terminal } = step;\n if (index + 1 === entries.length + (terminal ? 1 : 0)) {\n steps.push({ jump: undefined, kind: \"finish\", label: end });\n } else {\n const preferred = newLabel(builder);\n const next = newLabel(builder);\n emit(builder, { alternative: next, kind: \"fork\", preferred }, span);\n placeLabel(builder, preferred);\n steps.push({ ...step, index: index + 1 });\n steps.push({ jump: end, kind: \"finish\", label: next });\n }\n const entry = entries[index];\n if (entry != null) {\n steps.push({ kind: \"node\", node: entry[1] });\n steps.push({ character: entry[0], kind: \"consume\" });\n }\n }\n}\n\nfunction buildClassValue(\n builder: Builder,\n value: ClassValue,\n backward: boolean,\n span: RegExpSpan,\n): void {\n if (value.strings.length === 0 && value.characters.length === 0) {\n emitClassValueBranch(builder, [], true, backward, span);\n return;\n }\n const branches: (() => void)[] = [];\n const nonEmptyStrings = value.strings.filter(\n (sequence) => sequence.length > 0,\n );\n if (nonEmptyStrings.length > 0) {\n const trie = classStringTrie(nonEmptyStrings, backward);\n branches.push(() => emitClassStringTrie(builder, trie, backward, span));\n }\n if (value.characters.length > 0) {\n branches.push(() =>\n emitClassValueBranch(builder, value.characters, true, backward, span),\n );\n }\n if (value.strings.some((sequence) => sequence.length === 0)) {\n branches.push(() => undefined);\n }\n emitClassAlternatives(builder, branches, span);\n}\n\n/** The lowest and highest capture index one atom encloses. */\nfunction captureBounds(\n atom: RegExpAtom,\n): readonly [number, number] | undefined {\n let first: number | undefined;\n let last: number | undefined;\n const note = (index: number): void => {\n first = first == null ? index : Math.min(first, index);\n last = last == null ? index : Math.max(last, index);\n };\n const visitDisjunction = (node: RegExpDisjunction): void => {\n for (const alternative of node.alternatives) {\n for (const term of alternative.terms) visitTerm(term);\n }\n };\n const visitAtom = (node: RegExpAtom): void => {\n if (node.kind === \"capturing-group\") {\n note(node.index);\n visitDisjunction(node.body);\n return;\n }\n if (node.kind === \"group\" || node.kind === \"modifier-group\") {\n visitDisjunction(node.body);\n }\n };\n const visitTerm = (term: RegExpTerm): void => {\n if (term.kind === \"assertion\") return;\n if (term.kind === \"lookaround\") {\n visitDisjunction(term.body);\n return;\n }\n visitAtom(term.kind === \"quantified\" ? term.atom : term);\n };\n visitAtom(atom);\n if (first == null || last == null) return undefined;\n return [first, last];\n}\n\nfunction buildAtom(\n builder: Builder,\n atom: RegExpAtom,\n backward: boolean,\n): void {\n const set = characterAtomSet(builder, atom);\n if (set != null) {\n emit(\n builder,\n { backward, kind: \"consume\", set: internSet(builder, set) },\n atom.span,\n );\n return;\n }\n if (atom.kind === \"class-set\") {\n buildClassValue(builder, classSetValue(builder, atom), backward, atom.span);\n return;\n }\n if (atom.kind === \"unicode-property\") {\n buildClassValue(\n builder,\n propertyEscapeClassValue(builder, atom),\n backward,\n atom.span,\n );\n return;\n }\n if (atom.kind === \"capturing-group\") {\n const start = 2 * atom.index;\n const end = start + 1;\n emit(builder, { kind: \"save\", slot: backward ? end : start }, atom.span);\n buildDisjunction(builder, atom.body, backward);\n emit(builder, { kind: \"save\", slot: backward ? start : end }, atom.span);\n return;\n }\n if (atom.kind === \"group\") {\n buildDisjunction(builder, atom.body, backward);\n return;\n }\n if (atom.kind === \"modifier-group\") {\n const dotAll = builder.dotAll;\n const ignoreCase = builder.ignoreCase;\n const multiline = builder.multiline;\n builder.dotAll =\n atom.enabled.includes(\"s\") || (dotAll && !atom.disabled.includes(\"s\"));\n builder.ignoreCase =\n atom.enabled.includes(\"i\") ||\n (ignoreCase && !atom.disabled.includes(\"i\"));\n builder.multiline =\n atom.enabled.includes(\"m\") || (multiline && !atom.disabled.includes(\"m\"));\n buildDisjunction(builder, atom.body, backward);\n builder.dotAll = dotAll;\n builder.ignoreCase = ignoreCase;\n builder.multiline = multiline;\n return;\n }\n if (atom.kind === \"backreference\" || atom.kind === \"named-backreference\") {\n const slots =\n atom.kind === \"backreference\"\n ? [2 * atom.index]\n : atom.indices.map((index: number) => 2 * index);\n emit(\n builder,\n {\n backward,\n ignoreCase: builder.ignoreCase,\n kind: \"backreference\",\n slots,\n },\n atom.span,\n );\n return;\n }\n refuse(\n \"unsupported\",\n \"This pattern atom has no matcher lowering yet.\",\n atom.span,\n );\n}\n\nfunction buildQuantified(\n builder: Builder,\n term: RegExpQuantified,\n backward: boolean,\n): void {\n const counter = allocateRegisters(builder, 2, term.span);\n const position = counter + 1;\n const bounds = captureBounds(term.atom);\n const head = newLabel(builder);\n const enter = newLabel(builder);\n const body = newLabel(builder);\n const exit = newLabel(builder);\n emit(builder, { counter, kind: \"repeat-init\" }, term.span);\n placeLabel(builder, head);\n emit(\n builder,\n {\n counter,\n enter,\n exit,\n greedy: term.quantifier.greedy,\n kind: \"repeat\",\n maximum: term.quantifier.maximum,\n minimum: term.quantifier.minimum,\n },\n term.span,\n );\n placeLabel(builder, enter);\n emit(\n builder,\n {\n body,\n clearFrom: bounds == null ? 0 : 2 * bounds[0],\n clearTo: bounds == null ? 0 : 2 * bounds[1] + 2,\n counter,\n kind: \"repeat-enter\",\n position,\n },\n term.span,\n );\n placeLabel(builder, body);\n buildAtom(builder, term.atom, backward);\n emit(\n builder,\n {\n counter,\n head,\n kind: \"repeat-end\",\n minimum: term.quantifier.minimum,\n position,\n },\n term.span,\n );\n placeLabel(builder, exit);\n}\n\nfunction buildAssertion(builder: Builder, term: RegExpEdgeAssertion): void {\n if (term.assertion === \"start\" || term.assertion === \"end\") {\n emit(\n builder,\n { assertion: term.assertion, kind: \"edge\", multiline: builder.multiline },\n term.span,\n );\n return;\n }\n const set =\n builder.wordSets.get(builder.ignoreCase) ??\n internSet(builder, wordCharacters(builder, term.span));\n builder.wordSets.set(builder.ignoreCase, set);\n emit(\n builder,\n {\n kind: \"boundary\",\n negated: term.assertion === \"non-word-boundary\",\n set,\n },\n term.span,\n );\n}\n\nfunction buildLookaround(builder: Builder, term: RegExpLookaround): void {\n const frame = allocateRegisters(builder, 1, term.span);\n const body = newLabel(builder);\n const exit = newLabel(builder);\n emit(\n builder,\n {\n body,\n frame,\n kind: \"look-start\",\n negated: term.negated,\n onFail: term.negated ? exit : builder.failLabel,\n },\n term.span,\n );\n placeLabel(builder, body);\n buildDisjunction(builder, term.body, term.direction === \"behind\");\n emit(\n builder,\n { exit, frame, kind: \"look-end\", negated: term.negated },\n term.span,\n );\n placeLabel(builder, exit);\n}\n\nfunction buildTerm(\n builder: Builder,\n term: RegExpTerm,\n backward: boolean,\n): void {\n if (term.kind === \"assertion\") {\n buildAssertion(builder, term);\n return;\n }\n if (term.kind === \"lookaround\") {\n buildLookaround(builder, term);\n return;\n }\n if (term.kind === \"quantified\") {\n buildQuantified(builder, term, backward);\n return;\n }\n buildAtom(builder, term, backward);\n}\n\n/**\n * Emit one alternative in evaluation order.\n *\n * A backward alternative evaluates its rightmost term first, which is what\n * makes a lookbehind body read toward the start of the input.\n */\nfunction buildAlternative(\n builder: Builder,\n alternative: RegExpAlternative,\n backward: boolean,\n): void {\n const terms = backward ? alternative.terms.toReversed() : alternative.terms;\n for (const term of terms) buildTerm(builder, term, backward);\n}\n\nfunction buildDisjunction(\n builder: Builder,\n disjunction: RegExpDisjunction,\n backward: boolean,\n): void {\n const alternatives = disjunction.alternatives;\n const last = alternatives.length - 1;\n if (last === 0) {\n const only = alternatives[0];\n if (only != null) buildAlternative(builder, only, backward);\n return;\n }\n const end = newLabel(builder);\n for (const [index, alternative] of alternatives.entries()) {\n if (index === last) {\n buildAlternative(builder, alternative, backward);\n break;\n }\n const preferred = newLabel(builder);\n const next = newLabel(builder);\n emit(\n builder,\n { alternative: next, kind: \"fork\", preferred },\n alternative.span,\n );\n placeLabel(builder, preferred);\n buildAlternative(builder, alternative, backward);\n emit(builder, { kind: \"jump\", target: end }, alternative.span);\n placeLabel(builder, next);\n }\n placeLabel(builder, end);\n}\n\n/** Rewrite every label reference into the address it was placed at. */\nfunction resolveTargets(\n instruction: RegExpMatcherInstruction,\n addresses: readonly number[],\n): RegExpMatcherInstruction {\n const address = (label: number): number => addresses[label] ?? 0;\n if (instruction.kind === \"fork\") {\n return {\n alternative: address(instruction.alternative),\n kind: \"fork\",\n preferred: address(instruction.preferred),\n };\n }\n if (instruction.kind === \"jump\") {\n return { kind: \"jump\", target: address(instruction.target) };\n }\n if (instruction.kind === \"repeat\") {\n return {\n ...instruction,\n enter: address(instruction.enter),\n exit: address(instruction.exit),\n };\n }\n if (instruction.kind === \"repeat-enter\") {\n return { ...instruction, body: address(instruction.body) };\n }\n if (instruction.kind === \"repeat-end\") {\n return { ...instruction, head: address(instruction.head) };\n }\n if (instruction.kind === \"look-start\") {\n return {\n ...instruction,\n body: address(instruction.body),\n onFail: address(instruction.onFail),\n };\n }\n if (instruction.kind === \"look-end\") {\n return { ...instruction, exit: address(instruction.exit) };\n }\n return instruction;\n}\n\n/** Record every character whose canonical form is another character. */\nfunction canonicalizationTable(\n classes: readonly (readonly number[])[],\n): RegExpMatcherCanonicalization {\n const pairs: (readonly [number, number])[] = [];\n for (const members of classes) {\n if (members.length < 2) continue;\n const representative = members.reduce(\n (lowest, member) => Math.min(lowest, member),\n members[0] ?? 0,\n );\n for (const member of members) {\n if (member !== representative) pairs.push([member, representative]);\n }\n }\n const sorted = pairs.toSorted((first, second) => first[0] - second[0]);\n return {\n canonical: sorted.map(([, canonical]) => canonical),\n characters: sorted.map(([character]) => character),\n };\n}\n\n/** Whether one artifact compares two input characters under `i`. */\nfunction comparesCharacters(\n instructions: readonly RegExpMatcherInstruction[],\n): boolean {\n return instructions.some(\n (instruction) =>\n instruction.kind === \"backreference\" && instruction.ignoreCase,\n );\n}\n\n/**\n * Copy the pattern metadata one artifact keeps.\n *\n * An artifact must not alias a value its caller still owns. Freezing the\n * caller's arrays would change the pattern the caller passed in, and\n * sharing them would let a later write to that pattern change how the\n * artifact matches, which is the whole of the immutability contract.\n */\nfunction ownedFlags(flags: RegExpFlags): RegExpFlags {\n return Object.freeze({\n dotAll: flags.dotAll,\n global: flags.global,\n hasIndices: flags.hasIndices,\n ignoreCase: flags.ignoreCase,\n multiline: flags.multiline,\n sticky: flags.sticky,\n text: flags.text,\n unicode: flags.unicode,\n unicodeSets: flags.unicodeSets,\n });\n}\n\nfunction ownedCaptures(\n captures: readonly RegExpCapture[],\n): readonly RegExpCapture[] {\n return Object.freeze(\n captures.map((capture) =>\n Object.freeze({\n index: capture.index,\n span: Object.freeze({\n end: capture.span.end,\n start: capture.span.start,\n }),\n ...includePropertiesWhen(() => {\n if (capture.name == null) return undefined;\n return { name: capture.name };\n }),\n }),\n ),\n );\n}\n\nfunction freezeProgram(program: RegExpMatcherProgram): RegExpMatcherProgram {\n for (const instruction of program.instructions) {\n if (instruction.kind === \"backreference\") Object.freeze(instruction.slots);\n Object.freeze(instruction);\n }\n Object.freeze(program.sets);\n Object.freeze(program.instructions);\n const table = program.canonicalization;\n if (table != null) {\n Object.freeze(table.canonical);\n Object.freeze(table.characters);\n Object.freeze(table);\n }\n return Object.freeze(program);\n}\n\n/**\n * Build the generic matcher artifact of one validated pattern.\n *\n * Every construct the pattern parser admits either compiles to defined\n * behavior here or is refused with a located error. Nothing is\n * approximated: a construct whose matcher semantics this unit does not own\n * and a Unicode fact its caller did not supply both stop the build rather\n * than producing an artifact that matches something else.\n */\nexport function buildRegExpMatcher(\n pattern: RegExpPattern,\n options: RegExpMatcherOptions = {},\n): RegExpMatcherResult {\n const limits = options.limits ?? defaultRegExpMatcherLimits;\n checkRegExpMatcherBound(limits.instructions, \"An instruction limit\");\n checkRegExpMatcherBound(limits.registers, \"A register limit\");\n const flags = pattern.flags;\n const builder: Builder = {\n addresses: [unplacedLabel],\n caseRepresentatives: undefined,\n classes: undefined,\n dotAll: flags.dotAll,\n failLabel: 0,\n ignoreCase: flags.ignoreCase,\n instructions: [],\n limits,\n lowered: 0,\n multiline: flags.multiline,\n registers: 2 * (pattern.captures.length + 1),\n setIndices: new Map(),\n sets: [],\n unicodeData: options.unicodeData ?? {},\n unicodeMode: regExpUnicodeMode(flags),\n unicodeSets: flags.unicodeSets,\n wordSets: new Map(),\n };\n const whole: RegExpSpan = { end: pattern.source.length, start: 0 };\n try {\n if (builder.registers > limits.registers) {\n refuse(\n \"limit\",\n \"A pattern needs more matcher registers than the reviewed limit.\",\n whole,\n );\n }\n emit(builder, { kind: \"save\", slot: 0 }, whole);\n buildDisjunction(builder, pattern.body, false);\n emit(builder, { kind: \"save\", slot: 1 }, whole);\n emit(builder, { kind: \"accept\" }, whole);\n placeLabel(builder, builder.failLabel);\n emit(builder, { kind: \"fail\" }, whole);\n const instructions = builder.instructions.map((instruction) =>\n resolveTargets(instruction, builder.addresses),\n );\n const program: RegExpMatcherProgram = {\n captures: ownedCaptures(pattern.captures),\n flags: ownedFlags(flags),\n groupNames: Object.freeze([...pattern.groupNames]),\n instructions,\n kind: \"matcher\",\n registers: builder.registers,\n sets: builder.sets,\n source: pattern.source,\n unicodeMode: builder.unicodeMode,\n ...includePropertiesWhen(() => {\n if (!comparesCharacters(instructions)) return undefined;\n return {\n canonicalization: canonicalizationTable(caseClasses(builder, whole)),\n };\n }),\n };\n return { built: true, errors: [], program: freezeProgram(program) };\n } catch (error) {\n if (error instanceof MatcherFailure) {\n return { built: false, errors: [error.error] };\n }\n throw error;\n }\n}\n"],"mappings":";;;AAsBA,SAAS,sBACP,YACoD;CACpD,OAAO,WAAW,KAAK,CAAC;AAC1B;;AAGA,MAAM,mBAAmB;;AAGzB,MAAM,iBAAiB;;AAmBvB,SAAS,OAAO,KAAuB,WAA4B;CACjE,IAAI,MAAM;CACV,IAAI,OAAO,IAAI;CACf,OAAO,MAAM,MAAM;EACjB,MAAM,SAAU,MAAM,QAAS;EAC/B,KAAK,IAAI,WAAW,MAAM,WAAW,MAAM,SAAS;OAC/C,OAAO;CACd;CACA,QAAQ,MAAM,OAAO;AACvB;;AAGA,SAAS,WAAW,OAAe,KAA+B;CAChE,OAAO,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC;AAC3C;;AAGA,SAAS,SACP,MACA,OACkB;CAClB,MAAM,aAAuB,CAAC;CAC9B,IAAI,YAAY;CAChB,IAAI,aAAa;CACjB,IAAI,QAAQ;CACZ,OAAO,YAAY,KAAK,UAAU,aAAa,MAAM,QAAQ;EAC3D,MAAM,YAAY,KAAK,cAAc;EACrC,MAAM,aAAa,MAAM,eAAe;EACxC,MAAM,QAAQ,KAAK,IAAI,WAAW,UAAU;EAC5C,IAAI,UAAU;EACd,IAAI,cAAc,OAAO;GACvB,YAAY,YAAY,OAAO,IAAI,IAAI;GACvC,aAAa;EACf;EACA,IAAI,eAAe,OAAO;GACxB,YAAY,aAAa,OAAO,IAAI,IAAI;GACxC,cAAc;EAChB;EACA,MAAM,WAAW;EACjB,SAAS;EACT,IAAI,aAAa,KAAK,QAAQ,GAAG,WAAW,KAAK,KAAK;OACjD,IAAI,WAAW,KAAK,UAAU,GAAG,WAAW,KAAK,KAAK;CAC7D;CACA,OAAO;AACT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,KACF;EAEF,KAAK,SAAS;GAAE,MAAM;GAAQ,MAAM;EAAE,GAAG,KAAK;EAC9C,iBAAiB,SAAS,QAAQ,MAAM,KAAK;EAC7C,KAAK,SAAS;GAAE,MAAM;GAAQ,MAAM;EAAE,GAAG,KAAK;EAC9C,KAAK,SAAS,EAAE,MAAM,SAAS,GAAG,KAAK;EACvC,WAAW,SAAS,QAAQ,SAAS;EACrC,KAAK,SAAS,EAAE,MAAM,OAAO,GAAG,KAAK;EACrC,MAAM,eAAe,QAAQ,aAAa,KAAK,gBAC7C,eAAe,aAAa,QAAQ,SAAS,CAC/C;EAkBA,OAAO;GAAE,OAAO;GAAM,QAAQ,CAAC;GAAG,SAAS,cAAc;IAhBvD,UAAU,cAAc,QAAQ,QAAQ;IACxC,OAAO,WAAW,KAAK;IACvB,YAAY,OAAO,OAAO,CAAC,GAAG,QAAQ,UAAU,CAAC;IACjD;IACA,MAAM;IACN,WAAW,QAAQ;IACnB,MAAM,QAAQ;IACd,QAAQ,QAAQ;IAChB,aAAa,QAAQ;IACrB,GAAG,4BAA4B;KAC7B,IAAI,CAAC,mBAAmB,YAAY,GAAG,OAAO;KAC9C,OAAO,EACL,kBAAkB,sBAAsB,YAAY,SAAS,KAAK,CAAC,EACrE;IACF,CAAC;GAE4D,CAAC;EAAE;CACpE,SAAS,OAAO;EACd,IAAI,iBAAiB,gBACnB,OAAO;GAAE,OAAO;GAAO,QAAQ,CAAC,MAAM,KAAK;EAAE;EAE/C,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"regexp-matcher.js","names":[],"sources":["../src/regexp-matcher.ts"],"sourcesContent":["/*\n * Oseo, an ahead-of-time compiler for JavaScript and TypeScript.\n * Copyright (C) 2026 Hong Minhee <https://hongminhee.org/>\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\n */\n\nimport {\n regExpUnicodeMode,\n type RegExpAlternative,\n type RegExpAtom,\n type RegExpCapture,\n type RegExpCharacterClass,\n type RegExpClassSetOperand,\n type RegExpClassEscapeSet,\n type RegExpClassItem,\n type RegExpDisjunction,\n type RegExpEdgeAssertion,\n type RegExpFlags,\n type RegExpLookaround,\n type RegExpPattern,\n type RegExpPatternError,\n type RegExpQuantified,\n type RegExpSpan,\n type RegExpTerm,\n type RegExpUnicodePropertyEscape,\n type RegExpUnicodeClassSet,\n} from \"./regexp.ts\";\n\nfunction includePropertiesWhen<const Properties extends object>(\n properties: () => Properties | undefined,\n): Properties | { [Key in keyof Properties]?: never } {\n return properties() ?? {};\n}\n\n/** The largest Unicode code point. */\nconst maximumCodePoint = 0x10_ffff;\n\n/** One past the largest code point, the only non-code-point boundary. */\nconst codePointLimit = maximumCodePoint + 1;\n\n/**\n * One immutable character set as an inversion list.\n *\n * The list is a strictly increasing, even-length array of boundaries where\n * membership toggles, so `[0x41, 0x5b]` is U+0041 through U+005A. A closing\n * boundary may equal one past the largest code point, which is the only\n * value the list may hold that is not itself a code point.\n *\n * `@oseo/unicode` publishes its tables in exactly this shape, so a table\n * reaches an artifact without being reshaped. The compiler core links no\n * Unicode data, so the few set operations the builder needs are implemented\n * here rather than imported: the dependency direction, not the duplication,\n * is what the package boundary protects.\n */\nexport type RegExpMatcherSet = readonly number[];\n\n/** Whether one inversion list holds one code point. */\nfunction setHas(set: RegExpMatcherSet, codePoint: number): boolean {\n let low = 0;\n let high = set.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n if ((set[middle] ?? 0) <= codePoint) low = middle + 1;\n else high = middle;\n }\n return (low & 1) === 1;\n}\n\n/** One inclusive code-point range as an inversion list. */\nfunction setOfRange(start: number, end: number): RegExpMatcherSet {\n return start > end ? [] : [start, end + 1];\n}\n\n/** The union of two inversion lists. */\nfunction setUnion(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n): RegExpMatcherSet {\n const boundaries: number[] = [];\n let leftIndex = 0;\n let rightIndex = 0;\n let depth = 0;\n while (leftIndex < left.length || rightIndex < right.length) {\n const leftValue = left[leftIndex] ?? codePointLimit + 1;\n const rightValue = right[rightIndex] ?? codePointLimit + 1;\n const value = Math.min(leftValue, rightValue);\n let opening = 0;\n if (leftValue === value) {\n opening += (leftIndex & 1) === 0 ? 1 : -1;\n leftIndex += 1;\n }\n if (rightValue === value) {\n opening += (rightIndex & 1) === 0 ? 1 : -1;\n rightIndex += 1;\n }\n const previous = depth;\n depth += opening;\n if (previous === 0 && depth > 0) boundaries.push(value);\n else if (previous > 0 && depth === 0) boundaries.push(value);\n }\n return boundaries;\n}\n\n/**\n * A running union of inversion lists, held as one partial union per rank.\n *\n * Slot `rank` holds the union of a run of exactly `2 ** rank` lists, so\n * adding one list carries upward the way a binary counter does. Every\n * boundary then takes part in a logarithmic number of merges rather than\n * in one merge for each list that follows it, and the accumulator holds\n * one partial union per rank rather than one per list.\n *\n * Folding `setUnion` from the left instead rewalks the whole accumulated\n * list once per operand, which is the square of the operand count for a\n * union whose operands name distinct code points. Collecting the lists\n * and merging them at the end holds every operand at once, which a union\n * of many large operands cannot afford.\n */\ntype SetUnionSlots = (RegExpMatcherSet | undefined)[];\n\n/** Add one inversion list to a running union. */\nfunction addSetUnion(slots: SetUnionSlots, set: RegExpMatcherSet): void {\n let carry = set;\n for (let rank = 0; ; rank += 1) {\n const held = slots[rank];\n if (held == null) {\n slots[rank] = carry;\n return;\n }\n slots[rank] = undefined;\n carry = setUnion(held, carry);\n }\n}\n\n/** The union every slot of a running union holds together. */\nfunction finishSetUnion(slots: SetUnionSlots): RegExpMatcherSet {\n let union: RegExpMatcherSet = [];\n for (const held of slots) {\n if (held != null) union = setUnion(union, held);\n }\n return union;\n}\n\n/** The complement of one inversion list over the whole code-point range. */\nfunction setComplement(set: RegExpMatcherSet): RegExpMatcherSet {\n const boundaries: number[] = [];\n let position = 0;\n for (let index = 0; index + 1 < set.length; index += 2) {\n const start = set[index] ?? 0;\n if (start > position) boundaries.push(position, start);\n position = set[index + 1] ?? 0;\n }\n if (position < codePointLimit) boundaries.push(position, codePointLimit);\n return boundaries;\n}\n\nfunction combineSets(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n include: (inLeft: boolean, inRight: boolean) => boolean,\n): RegExpMatcherSet {\n const points = [...new Set([0, ...left, ...right, codePointLimit])].toSorted(\n (first, second) => first - second,\n );\n const result: number[] = [];\n let included = false;\n for (let index = 0; index + 1 < points.length; index += 1) {\n const point = points[index] ?? 0;\n const next = include(setHas(left, point), setHas(right, point));\n if (next !== included) result.push(point);\n included = next;\n }\n if (included) result.push(codePointLimit);\n return result;\n}\n\n/** The intersection of two inversion lists. */\nfunction setIntersection(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n): RegExpMatcherSet {\n return combineSets(left, right, (inLeft, inRight) => inLeft && inRight);\n}\n\n/** The members of the first inversion list absent from the second. */\nfunction setDifference(\n left: RegExpMatcherSet,\n right: RegExpMatcherSet,\n): RegExpMatcherSet {\n return combineSets(left, right, (inLeft, inRight) => inLeft && !inRight);\n}\n\n/** Build a normalized inversion list from unsorted inclusive ranges. */\nfunction setOfRanges(\n ranges: readonly (readonly [number, number])[],\n): RegExpMatcherSet {\n const sorted = ranges\n .filter(([start, end]) => start <= end)\n .toSorted((first, second) => first[0] - second[0]);\n const boundaries: number[] = [];\n for (const [start, end] of sorted) {\n const last = boundaries.length - 1;\n const previousEnd = boundaries[last];\n if (previousEnd != null && start <= previousEnd) {\n if (end + 1 > previousEnd) boundaries[last] = end + 1;\n continue;\n }\n boundaries.push(start, end + 1);\n }\n return boundaries;\n}\n\n/** The four code points the LineTerminator production names. */\nconst lineTerminators: RegExpMatcherSet = setOfRanges([\n [0x0a, 0x0a],\n [0x0d, 0x0d],\n [0x20_28, 0x20_29],\n]);\n\n/** The sixty-three characters `WordCharacters` calls basic. */\nconst basicWordCharacters: RegExpMatcherSet = setOfRanges([\n [0x30, 0x39],\n [0x41, 0x5a],\n [0x5f, 0x5f],\n [0x61, 0x7a],\n]);\n\n/** The decimal digits `\\d` names. */\nconst decimalDigits: RegExpMatcherSet = setOfRange(0x30, 0x39);\n\n/** The whitespace `\\s` names apart from `General_Category=Space_Separator`. */\nconst namedWhiteSpace: RegExpMatcherSet = setOfRanges([\n [0x09, 0x09],\n [0x0b, 0x0c],\n [0xfe_ff, 0xfe_ff],\n]);\n\n/**\n * One code point that canonicalizes to another, recorded for execution.\n *\n * `characters` is strictly increasing and `canonical` holds the canonical\n * form of the character at the same offset. A character the table omits\n * canonicalizes to itself. The executor needs this only where a\n * backreference compares two input characters under `i`; every other\n * ignore-case decision is folded into a set while the artifact is built.\n */\nexport interface RegExpMatcherCanonicalization {\n readonly canonical: readonly number[];\n readonly characters: readonly number[];\n}\n\n/** Consume one character of the input in the instruction's direction. */\nexport interface RegExpMatcherConsume {\n readonly backward: boolean;\n readonly kind: \"consume\";\n readonly set: number;\n}\n\n/** Assert `^` or `$` at the current position. */\nexport interface RegExpMatcherEdge {\n readonly assertion: \"end\" | \"start\";\n readonly kind: \"edge\";\n readonly multiline: boolean;\n}\n\n/** Assert `\\b` or `\\B` at the current position. */\nexport interface RegExpMatcherBoundary {\n readonly kind: \"boundary\";\n readonly negated: boolean;\n readonly set: number;\n}\n\n/** Record the current position in one capture register. */\nexport interface RegExpMatcherSave {\n readonly kind: \"save\";\n readonly slot: number;\n}\n\n/** Reset a contiguous capture register range to unset. */\nexport interface RegExpMatcherClear {\n readonly from: number;\n readonly kind: \"clear\";\n readonly to: number;\n}\n\n/** Try one continuation first and keep the other for backtracking. */\nexport interface RegExpMatcherFork {\n readonly alternative: number;\n readonly kind: \"fork\";\n readonly preferred: number;\n}\n\n/** Continue at one address. */\nexport interface RegExpMatcherJump {\n readonly kind: \"jump\";\n readonly target: number;\n}\n\n/**\n * Decide whether one repetition iterates again.\n *\n * Below `minimum` the iteration is forced, at `maximum` the repetition\n * exits, and between them `greedy` orders the two continuations. The\n * decision never inspects the input, so a repetition is one loop in the\n * artifact whatever its bounds say.\n */\nexport interface RegExpMatcherRepeat {\n readonly counter: number;\n readonly enter: number;\n readonly exit: number;\n readonly greedy: boolean;\n readonly kind: \"repeat\";\n readonly maximum: number;\n readonly minimum: number;\n}\n\n/**\n * Begin one repetition, discarding the count of any earlier entry.\n *\n * The edition gives every entry into a quantified atom a fresh repetition\n * state, so a repetition nested in another one starts over each time the\n * outer body runs rather than resuming the count it left behind.\n */\nexport interface RegExpMatcherRepeatInit {\n readonly counter: number;\n readonly kind: \"repeat-init\";\n}\n\n/** Start one repetition iteration, clearing the captures it may set. */\nexport interface RegExpMatcherRepeatEnter {\n readonly body: number;\n readonly clearFrom: number;\n readonly clearTo: number;\n readonly counter: number;\n readonly kind: \"repeat-enter\";\n readonly position: number;\n}\n\n/**\n * Finish one repetition iteration.\n *\n * An iteration that consumed nothing fails once the repetition has met its\n * lower bound, which is what stops an empty body from repeating forever\n * while still letting the bound itself be satisfied by empty iterations.\n */\nexport interface RegExpMatcherRepeatEnd {\n readonly counter: number;\n readonly head: number;\n readonly kind: \"repeat-end\";\n readonly minimum: number;\n readonly position: number;\n}\n\n/**\n * Enter one lookaround body.\n *\n * The instruction records the backtrack height its body may not unwind\n * past, so the body's own choices are discarded when it finishes.\n * `onFail` is where the assertion continues once its body has no match\n * left: the shared failure instruction for a positive assertion, and the\n * instruction after the assertion for a negative one, which is the only\n * way a negative assertion succeeds.\n */\nexport interface RegExpMatcherLookStart {\n readonly body: number;\n readonly frame: number;\n readonly kind: \"look-start\";\n readonly negated: boolean;\n readonly onFail: number;\n}\n\n/**\n * Leave one lookaround body that matched.\n *\n * A positive assertion restores the entry position, keeps the captures the\n * body set, and discards the body's remaining choices. A negative\n * assertion undoes both and fails.\n */\nexport interface RegExpMatcherLookEnd {\n readonly exit: number;\n readonly frame: number;\n readonly kind: \"look-end\";\n readonly negated: boolean;\n}\n\n/**\n * Match the text one earlier capture holds.\n *\n * `slots` names every capture a group name resolves to, in ascending\n * index order. At most one of them can have participated in the match, and\n * a reference to a capture that did not participate matches the empty\n * string rather than failing.\n */\nexport interface RegExpMatcherBackreference {\n readonly backward: boolean;\n readonly ignoreCase: boolean;\n readonly kind: \"backreference\";\n readonly slots: readonly number[];\n}\n\n/** Report the whole pattern as matched. */\nexport interface RegExpMatcherAccept {\n readonly kind: \"accept\";\n}\n\n/** Abandon the current path and backtrack. */\nexport interface RegExpMatcherFail {\n readonly kind: \"fail\";\n}\n\n/** One instruction of a matcher artifact. */\nexport type RegExpMatcherInstruction =\n | RegExpMatcherAccept\n | RegExpMatcherBackreference\n | RegExpMatcherBoundary\n | RegExpMatcherClear\n | RegExpMatcherConsume\n | RegExpMatcherEdge\n | RegExpMatcherFail\n | RegExpMatcherFork\n | RegExpMatcherJump\n | RegExpMatcherLookEnd\n | RegExpMatcherLookStart\n | RegExpMatcherRepeat\n | RegExpMatcherRepeatEnd\n | RegExpMatcherRepeatEnter\n | RegExpMatcherRepeatInit\n | RegExpMatcherSave;\n\n/**\n * One immutable matcher artifact.\n *\n * The artifact is the semantic authority for one pattern: an ahead-of-time\n * lowering and any later fast path must produce the match state this\n * program produces. It holds no mutable field and no reference to a\n * regular expression object, so equal artifacts may be shared while every\n * evaluation still owns its own object identity and `lastIndex`.\n *\n * Register 0 and 1 hold the whole match, and registers `2 * index` and\n * `2 * index + 1` hold capturing group `index`. The remaining registers\n * are repetition counters, repetition positions, and lookaround frames.\n */\nexport interface RegExpMatcherProgram {\n readonly canonicalization?: RegExpMatcherCanonicalization;\n readonly captures: readonly RegExpCapture[];\n readonly flags: RegExpFlags;\n readonly groupNames: readonly string[];\n readonly instructions: readonly RegExpMatcherInstruction[];\n readonly kind: \"matcher\";\n readonly registers: number;\n readonly sets: readonly RegExpMatcherSet[];\n readonly source: string;\n readonly unicodeMode: boolean;\n}\n\n/**\n * Unicode facts the builder cannot derive on its own.\n *\n * The compiler core links no Unicode data, so a caller that owns the\n * pinned tables supplies the raw facts and the builder owns every\n * ECMAScript decision made from them. A pattern whose grammar needs a fact\n * the caller did not supply is refused with a located error rather than\n * matched against a guess.\n *\n * `caseEquivalenceClasses` returns every class of two or more characters\n * that `Canonicalize` maps together for the given mode, which is simple\n * case folding under `u` or `v` and the single-code-unit uppercase rule\n * otherwise. Classes of one character are omitted because they change\n * nothing.\n */\nexport interface RegExpMatcherUnicodeData {\n readonly caseEquivalenceClasses?: (\n unicodeMode: boolean,\n ) => readonly (readonly number[])[];\n readonly propertySet?: (\n escape: RegExpUnicodePropertyEscape,\n ) => RegExpMatcherSet | undefined;\n readonly stringPropertySet?: (\n escape: RegExpUnicodePropertyEscape,\n ) => readonly (readonly number[])[] | undefined;\n readonly generalCategoryValue?: (name: string) => boolean;\n readonly spaceSeparators?: RegExpMatcherSet;\n}\n\n/**\n * Owned boundaries applied while one artifact is built.\n *\n * A pattern the parser already accepted stays within these for any\n * ordinary source, so reaching one reports a located `limit` error rather\n * than producing an artifact whose storage a later native lowering could\n * not describe.\n */\nexport interface RegExpMatcherLimits {\n /**\n * The lowered instruction count, which charges a backreference to a\n * duplicated group name once per candidate capture because that is\n * what a native encoding writes for it.\n */\n readonly instructions: number;\n readonly registers: number;\n}\n\n/** The reviewed default artifact limits. */\nexport const defaultRegExpMatcherLimits: RegExpMatcherLimits = {\n instructions: 0x10_0000,\n registers: 0x4_0000,\n};\n\n/** Optional components of one artifact build. */\nexport interface RegExpMatcherOptions {\n readonly limits?: RegExpMatcherLimits;\n readonly unicodeData?: RegExpMatcherUnicodeData;\n}\n\n/**\n * The outcome of one build.\n *\n * `program` is present exactly when `built` is true, and `errors` is\n * nonempty exactly when it is false.\n */\nexport interface RegExpMatcherResult {\n readonly built: boolean;\n readonly errors: readonly RegExpPatternError[];\n readonly program?: RegExpMatcherProgram;\n}\n\n/**\n * Reject a boundary a caller supplied that is not a count.\n *\n * A limit that is not a nonnegative safe integer would silently disable\n * the boundary it names, because every comparison against it is false.\n * That is a caller defect rather than a pattern the unit cannot describe,\n * so it throws instead of reporting a located pattern error.\n */\nexport function checkRegExpMatcherBound(value: number, subject: string): void {\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new RangeError(`${subject} must be a nonnegative safe integer.`);\n }\n}\n\n/** One rejected construct, thrown so a deep production keeps its span. */\nclass MatcherFailure extends Error {\n readonly error: RegExpPatternError;\n\n constructor(error: RegExpPatternError) {\n super(error.message);\n this.error = error;\n }\n}\n\nfunction refuse(\n kind: \"limit\" | \"unsupported\",\n message: string,\n span: RegExpSpan,\n): never {\n throw new MatcherFailure({ kind, message, section: \"pattern\", span });\n}\n\n/** The address a label holds until it is placed. */\nconst unplacedLabel = -1;\n\n/**\n * The emitter state of one build.\n *\n * A target field holds a label while instructions are emitted and the\n * address the label was placed at afterwards, so a forward branch never\n * needs a mutable instruction.\n */\ninterface Builder {\n readonly addresses: number[];\n readonly failLabel: number;\n readonly instructions: RegExpMatcherInstruction[];\n readonly limits: RegExpMatcherLimits;\n readonly setIndices: Map<string, number>;\n readonly sets: RegExpMatcherSet[];\n readonly unicodeData: RegExpMatcherUnicodeData;\n readonly unicodeMode: boolean;\n readonly unicodeSets: boolean;\n caseRepresentatives: ReadonlyMap<number, number> | undefined;\n classes: readonly (readonly number[])[] | undefined;\n dotAll: boolean;\n ignoreCase: boolean;\n /**\n * How many instructions a native encoding of this artifact needs.\n *\n * Every instruction is one except a backreference to a duplicated group\n * name, which a lowering writes as one instruction per candidate\n * capture because at most one of them can have participated. Charging\n * that expansion here is what keeps the reviewed instruction limit a\n * bound on the storage a later native lowering has to describe rather\n * than on this array's length alone.\n */\n lowered: number;\n multiline: boolean;\n registers: number;\n readonly wordSets: Map<boolean, number>;\n}\n\nfunction newLabel(builder: Builder): number {\n builder.addresses.push(unplacedLabel);\n return builder.addresses.length - 1;\n}\n\nfunction placeLabel(builder: Builder, label: number): void {\n builder.addresses[label] = builder.instructions.length;\n}\n\nfunction emit(\n builder: Builder,\n instruction: RegExpMatcherInstruction,\n span: RegExpSpan,\n): void {\n const cost =\n instruction.kind === \"backreference\"\n ? Math.max(instruction.slots.length, 1)\n : 1;\n if (builder.lowered + cost > builder.limits.instructions) {\n refuse(\n \"limit\",\n \"A pattern needs more matcher instructions than the reviewed limit.\",\n span,\n );\n }\n builder.lowered += cost;\n builder.instructions.push(instruction);\n}\n\nfunction allocateRegisters(\n builder: Builder,\n count: number,\n span: RegExpSpan,\n): number {\n if (builder.registers + count > builder.limits.registers) {\n refuse(\n \"limit\",\n \"A pattern needs more matcher registers than the reviewed limit.\",\n span,\n );\n }\n const base = builder.registers;\n builder.registers += count;\n return base;\n}\n\n/**\n * Intern one set, so equal sets share one artifact entry.\n *\n * The stored list is a frozen copy. A set may have arrived from the\n * caller's Unicode tables, and an artifact must neither freeze a table the\n * caller still owns nor keep a list the caller could rewrite later.\n */\nfunction internSet(builder: Builder, set: RegExpMatcherSet): number {\n const key = set.join(\",\");\n const existing = builder.setIndices.get(key);\n if (existing != null) return existing;\n const index = builder.sets.length;\n builder.sets.push(Object.freeze([...set]));\n builder.setIndices.set(key, index);\n return index;\n}\n\nfunction caseClasses(\n builder: Builder,\n span: RegExpSpan,\n): readonly (readonly number[])[] {\n const cached = builder.classes;\n if (cached != null) return cached;\n const provide = builder.unicodeData.caseEquivalenceClasses;\n if (provide == null) {\n refuse(\n \"unsupported\",\n \"An ignore-case pattern needs case folding data that is not linked.\",\n span,\n );\n }\n const classes = provide(builder.unicodeMode);\n builder.classes = classes;\n return classes;\n}\n\n/**\n * Close one set under the pattern's canonicalization.\n *\n * `CharacterSetMatcher` compares the canonical form of the input character\n * with the canonical form of every set member, so a set matches exactly\n * the characters whose equivalence class meets it. Only a character with a\n * case sibling can join a set it was not already in, so closing walks the\n * equivalence classes rather than the whole code-point range.\n */\nfunction closeSet(\n builder: Builder,\n set: RegExpMatcherSet,\n span: RegExpSpan,\n): RegExpMatcherSet {\n if (!builder.ignoreCase) return set;\n const added: (readonly [number, number])[] = [];\n for (const members of caseClasses(builder, span)) {\n if (!members.some((member) => setHas(set, member))) continue;\n for (const member of members) {\n if (!setHas(set, member)) added.push([member, member]);\n }\n }\n return added.length === 0 ? set : setUnion(set, setOfRanges(added));\n}\n\n/** Map each cased character to one stable representative of its class. */\nfunction caseRepresentatives(\n builder: Builder,\n span: RegExpSpan,\n): ReadonlyMap<number, number> {\n const cached = builder.caseRepresentatives;\n if (cached != null) return cached;\n const representatives = new Map<number, number>();\n for (const members of caseClasses(builder, span)) {\n const representative = members.reduce(\n (lowest, member) => Math.min(lowest, member),\n members[0] ?? 0,\n );\n for (const member of members) representatives.set(member, representative);\n }\n builder.caseRepresentatives = representatives;\n return representatives;\n}\n\n/**\n * The `WordCharacters` of this pattern.\n *\n * The edition adds a character outside the basic sixty-three only when\n * both `i` and a unicode-mode flag are set, and closing the basic set\n * under the non-unicode case rule adds nothing, so one expression covers\n * every flag combination.\n */\nfunction wordCharacters(builder: Builder, span: RegExpSpan): RegExpMatcherSet {\n return closeSet(builder, basicWordCharacters, span);\n}\n\nfunction spaceCharacters(builder: Builder, span: RegExpSpan): RegExpMatcherSet {\n const separators = builder.unicodeData.spaceSeparators;\n if (separators == null) {\n refuse(\n \"unsupported\",\n \"A whitespace class escape needs Unicode category data that is not \" +\n \"linked.\",\n span,\n );\n }\n return setUnion(setUnion(namedWhiteSpace, separators), lineTerminators);\n}\n\n/** The raw set one `\\d`, `\\s`, or `\\w` escape names, before closing. */\nfunction classEscapeSet(\n builder: Builder,\n set: RegExpClassEscapeSet,\n span: RegExpSpan,\n): RegExpMatcherSet {\n if (set === \"digit\") return decimalDigits;\n if (set === \"space\") return spaceCharacters(builder, span);\n return wordCharacters(builder, span);\n}\n\nfunction propertyEscapeSet(\n builder: Builder,\n escape: RegExpUnicodePropertyEscape,\n): RegExpMatcherSet {\n const resolve = builder.unicodeData.propertySet;\n if (resolve == null) {\n refuse(\n \"unsupported\",\n \"A Unicode property escape needs property data that is not linked.\",\n escape.span,\n );\n }\n const resolved = resolve(escape);\n if (resolved == null) {\n refuse(\n \"unsupported\",\n \"This Unicode property names no code-point set.\",\n escape.span,\n );\n }\n if (!escape.negated) return resolved;\n /*\n * The two unicode-mode flags complement a property differently. `v`\n * folds the property first and complements it over the folded code\n * points, so `\\P{Ll}` under `iv` excludes every character equivalent to\n * a lowercase letter. `u` complements the unfolded property instead and\n * lets `CharacterSetMatcher` close the result afterwards, so the same\n * escape under `iu` accepts them. Closing a complemented closed set adds\n * nothing, so the outer closing stays a no-op here.\n */\n if (builder.unicodeSets && builder.ignoreCase) {\n return setComplement(closeSet(builder, resolved, escape.span));\n }\n return setComplement(resolved);\n}\n\ninterface ClassValue {\n readonly characters: RegExpMatcherSet;\n readonly strings: readonly (readonly number[])[];\n}\n\n/** The key two class strings share exactly when they hold the same run. */\nfunction classStringKey(sequence: readonly number[]): string {\n return sequence.join(\",\");\n}\n\n/**\n * Fold one class-set value into a running union of values.\n *\n * The edition holds a one-character `\\q{...}` alternative as a code point\n * rather than as a string, and holds each remaining alternative once. An\n * alternative already in `unique` is left as it was written, so a repeated\n * alternative keeps the spelling and the position of its first appearance,\n * which is the order the class string trie is then built in.\n *\n * `slots` and `unique` are the accumulator: folding is written this way so\n * that a union of many operands folds each operand a bounded number of\n * times and releases it, rather than refolding everything it already\n * holds once more for every operand that follows.\n */\nfunction addClassValue(\n slots: SetUnionSlots,\n unique: Map<string, readonly number[]>,\n value: ClassValue,\n): void {\n const single: (readonly [number, number])[] = [];\n for (const sequence of value.strings) {\n const character = sequence.length === 1 ? sequence[0] : undefined;\n if (character == null) {\n const key = classStringKey(sequence);\n if (!unique.has(key)) unique.set(key, sequence);\n continue;\n }\n single.push([character, character]);\n }\n addSetUnion(slots, value.characters);\n if (single.length > 0) addSetUnion(slots, setOfRanges(single));\n}\n\n/** One class-set value with its one-character alternatives folded in. */\nfunction normalizeClassValue(value: ClassValue): ClassValue {\n const slots: SetUnionSlots = [];\n const unique = new Map<string, readonly number[]>();\n addClassValue(slots, unique, value);\n return {\n characters: finishSetUnion(slots),\n strings: [...unique.values()],\n };\n}\n\nfunction propertyEscapeClassValue(\n builder: Builder,\n escape: RegExpUnicodePropertyEscape,\n): ClassValue {\n const characters = builder.unicodeData.propertySet?.(escape);\n if (characters != null) {\n return { characters: propertyEscapeSet(builder, escape), strings: [] };\n }\n const strings = builder.unicodeData.stringPropertySet?.(escape);\n if (strings == null || escape.negated) {\n refuse(\n \"unsupported\",\n \"A Unicode property of strings needs data that is not linked.\",\n escape.span,\n );\n }\n return normalizeClassValue({ characters: [], strings });\n}\n\n/**\n * Whether one escape is a lone General_Category value such as `\\p{Ll}`.\n *\n * `CompileToCharSet` returns that spelling without folding it, while the\n * `\\p{gc=Ll}` spelling and every binary property end in\n * `MaybeSimpleCaseFolding`. The asymmetry is deliberate and is only\n * observable inside `v`-mode set algebra, where folding an operand before\n * the operation removes members the edition keeps.\n *\n * The builder asks the question the edition asks, whether the name is a\n * General_Category value, through the caller's own data. Holding a table of\n * category names here would put Unicode knowledge in the compiler core,\n * which the package boundary does not allow.\n *\n * The caller answers it directly rather than the builder inferring it from\n * whether some other spelling resolves. A provider that resolves a lone\n * escape but not the classification would otherwise fold an operand the\n * edition keeps exact and match nothing, silently, where every other\n * missing Unicode fact reports an owned refusal.\n */\nfunction loneGeneralCategory(\n builder: Builder,\n escape: RegExpUnicodePropertyEscape,\n): boolean {\n if (escape.value != null) return false;\n const classify = builder.unicodeData.generalCategoryValue;\n if (classify == null) {\n refuse(\n \"unsupported\",\n \"A lone Unicode property escape needs the General_Category value \" +\n \"classification that is not linked.\",\n escape.span,\n );\n }\n return classify(escape.property);\n}\n\n/**\n * Whether one operand keeps its exact code points through set algebra.\n *\n * The edition folds a `ClassSetCharacter` and a `ClassStringDisjunction`\n * operand but returns a `NestedClass` operand unchanged, so a nested class\n * carries whatever its own operands decided rather than being folded again.\n * Closing a nested value that is already closed changes nothing, so this\n * only matters for the one leaf the edition leaves raw.\n */\nfunction preservesExactOperand(\n builder: Builder,\n operand: RegExpClassSetOperand,\n): boolean {\n if (operand.kind === \"class-set\") return true;\n return (\n operand.kind === \"unicode-property\" &&\n !operand.negated &&\n loneGeneralCategory(builder, operand)\n );\n}\n\nfunction classSetOperandValue(\n builder: Builder,\n operand: RegExpClassSetOperand,\n): ClassValue {\n let value: ClassValue;\n if (operand.kind === \"class-set\") {\n value = classSetValue(builder, operand);\n } else if (operand.kind === \"class-strings\") {\n value = normalizeClassValue({\n characters: [],\n strings: operand.strings.map((characters) =>\n characters.map((character) => character.value),\n ),\n });\n } else if (operand.kind === \"unicode-property\") {\n value = propertyEscapeClassValue(builder, operand);\n } else {\n value = { characters: classItemSet(builder, operand), strings: [] };\n }\n if (!builder.unicodeSets || !builder.ignoreCase) return value;\n const representatives = caseRepresentatives(builder, operand.span);\n const exact = preservesExactOperand(builder, operand);\n return normalizeClassValue({\n characters: exact\n ? value.characters\n : closeSet(builder, value.characters, operand.span),\n strings: value.strings.map((sequence) =>\n sequence.map((character) => representatives.get(character) ?? character),\n ),\n });\n}\n\n/** The first operand's value, or the empty value for no operand at all. */\nfunction leadingClassValue(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const first = operands[0];\n if (first == null) return { characters: [], strings: [] };\n return normalizeClassValue(classSetOperandValue(builder, first));\n}\n\n/**\n * The union of every operand, accumulated as the operands resolve.\n *\n * Unioning two values at a time renormalized every alternative the\n * accumulator already held, once per operand, which is the square of the\n * operand count: an admitted one-mebibyte source can write more than a\n * hundred thousand `\\q{...}` operands into one union. Each operand is\n * folded on its own instead, and the alternatives accumulate in a map\n * keyed the way `normalizeClassValue` keys them, so a repeated alternative\n * still keeps the position and spelling of its first appearance and the\n * result is the value the pairwise fold produced.\n *\n * One operand is resolved at a time and released once it has been folded\n * in, because a union of many operands that each name thousands of\n * alternatives cannot hold every operand's value at once.\n */\nfunction unionClassSet(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const slots: SetUnionSlots = [];\n const unique = new Map<string, readonly number[]>();\n for (const operand of operands) {\n addClassValue(slots, unique, classSetOperandValue(builder, operand));\n }\n return {\n characters: finishSetUnion(slots),\n strings: [...unique.values()],\n };\n}\n\n/**\n * The intersection of the first operand with every operand after it.\n *\n * An alternative of the first operand survives exactly when every later\n * operand also holds it, which one counting pass decides. Re-filtering the\n * survivors against each operand in turn would instead cost the first\n * operand's size once per operand. Only an alternative the first operand\n * wrote is counted, so the counts stay within its size however many\n * operands follow.\n */\nfunction intersectClassSet(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const left = leadingClassValue(builder, operands);\n const candidates = new Set(left.strings.map(classStringKey));\n const holders = new Map<string, number>();\n let characters = left.characters;\n let rights = 0;\n for (const [index, operand] of operands.entries()) {\n if (index === 0) continue;\n const value = classSetOperandValue(builder, operand);\n characters = setIntersection(characters, value.characters);\n for (const key of new Set(value.strings.map(classStringKey))) {\n if (!candidates.has(key)) continue;\n holders.set(key, (holders.get(key) ?? 0) + 1);\n }\n rights += 1;\n }\n return {\n characters,\n strings: left.strings.filter(\n (value) => (holders.get(classStringKey(value)) ?? 0) === rights,\n ),\n };\n}\n\n/**\n * The first operand less every operand after it.\n *\n * Difference is left-associative, and removing the operands in turn\n * removes exactly what removing their union removes, so an alternative\n * leaves the survivors the first time a later operand writes it rather\n * than being looked for again in every operand, which would cost the first\n * operand's size once per operand. Only what the first operand wrote is\n * tracked, so the survivors stay within its size however many alternatives\n * the later operands name, and each of their values is released once it\n * has been folded in.\n */\nfunction subtractClassSet(\n builder: Builder,\n operands: readonly RegExpClassSetOperand[],\n): ClassValue {\n const left = leadingClassValue(builder, operands);\n const slots: SetUnionSlots = [];\n const surviving = new Set(left.strings.map(classStringKey));\n for (const [index, operand] of operands.entries()) {\n if (index === 0) continue;\n const value = classSetOperandValue(builder, operand);\n addSetUnion(slots, value.characters);\n for (const sequence of value.strings) {\n surviving.delete(classStringKey(sequence));\n }\n }\n return {\n characters: setDifference(left.characters, finishSetUnion(slots)),\n strings: left.strings.filter((value) =>\n surviving.has(classStringKey(value)),\n ),\n };\n}\n\nfunction classSetValue(\n builder: Builder,\n node: RegExpUnicodeClassSet,\n): ClassValue {\n let value: ClassValue;\n if (node.operation === \"union\") {\n value = unionClassSet(builder, node.operands);\n } else if (node.operation === \"intersection\") {\n value = intersectClassSet(builder, node.operands);\n } else {\n value = subtractClassSet(builder, node.operands);\n }\n if (!node.negated) return value;\n if (value.strings.length > 0) {\n refuse(\n \"unsupported\",\n \"A negated class set cannot contain strings.\",\n node.span,\n );\n }\n /*\n * `CharacterComplement` complements over the folded code points under\n * `iv`, so a set that reached here holding the exact members of a lone\n * category is closed first. Complementing it raw would keep every case\n * sibling of its members, which is the opposite of what negation means\n * here. A set that is already closed is unchanged by this.\n */\n const complemented =\n builder.unicodeSets && builder.ignoreCase\n ? closeSet(builder, value.characters, node.span)\n : value.characters;\n return { characters: setComplement(complemented), strings: [] };\n}\n\n/** The raw set one class member names, before the class is closed. */\nfunction classItemSet(\n builder: Builder,\n item: RegExpClassItem,\n): RegExpMatcherSet {\n if (item.kind === \"character\") return setOfRange(item.value, item.value);\n if (item.kind === \"range\") {\n return setOfRange(item.start.value, item.end.value);\n }\n if (item.kind === \"class-escape\") {\n const named = classEscapeSet(builder, item.set, item.span);\n return item.negated ? setComplement(named) : named;\n }\n return propertyEscapeSet(builder, item);\n}\n\nfunction characterClassSet(\n builder: Builder,\n node: RegExpCharacterClass,\n): RegExpMatcherSet {\n let union: RegExpMatcherSet = [];\n for (const item of node.items) {\n union = setUnion(union, classItemSet(builder, item));\n }\n return union;\n}\n\n/**\n * The set one consuming atom matches, or undefined for another atom.\n *\n * Closing comes before negation because `CharacterSetMatcher` inverts a\n * class after canonicalizing its members: `[^a]` under `i` rejects `A`,\n * while closing the complement instead would accept it.\n */\nfunction characterAtomSet(\n builder: Builder,\n atom: RegExpAtom,\n): RegExpMatcherSet | undefined {\n if (atom.kind === \"character\") {\n return closeSet(builder, setOfRange(atom.value, atom.value), atom.span);\n }\n if (atom.kind === \"dot\") {\n const dot = builder.dotAll\n ? setOfRange(0, maximumCodePoint)\n : setComplement(lineTerminators);\n return closeSet(builder, dot, atom.span);\n }\n if (atom.kind === \"class-escape\") {\n const named = classEscapeSet(builder, atom.set, atom.span);\n return closeSet(\n builder,\n atom.negated ? setComplement(named) : named,\n atom.span,\n );\n }\n if (atom.kind === \"unicode-property\") {\n if (\n builder.unicodeData.propertySet?.(atom) == null &&\n builder.unicodeData.stringPropertySet?.(atom) != null\n ) {\n return undefined;\n }\n return closeSet(builder, propertyEscapeSet(builder, atom), atom.span);\n }\n if (atom.kind === \"class-set\") return undefined;\n if (atom.kind !== \"character-class\") return undefined;\n const closed = closeSet(builder, characterClassSet(builder, atom), atom.span);\n return atom.negated ? setComplement(closed) : closed;\n}\n\nfunction emitClassValueBranch(\n builder: Builder,\n sequence: readonly number[] | RegExpMatcherSet,\n characters: boolean,\n backward: boolean,\n span: RegExpSpan,\n): void {\n if (characters) {\n const closed = closeSet(builder, sequence, span);\n emit(\n builder,\n { backward, kind: \"consume\", set: internSet(builder, closed) },\n span,\n );\n return;\n }\n const ordered = backward ? sequence.toReversed() : sequence;\n for (const character of ordered) {\n const closed = closeSet(builder, setOfRange(character, character), span);\n emit(\n builder,\n { backward, kind: \"consume\", set: internSet(builder, closed) },\n span,\n );\n }\n}\n\ninterface ClassStringTrie {\n readonly children: Map<number, ClassStringTrie>;\n terminal: boolean;\n}\n\nfunction classStringTrie(\n sequences: readonly (readonly number[])[],\n backward: boolean,\n): ClassStringTrie {\n const root: ClassStringTrie = { children: new Map(), terminal: false };\n for (const source of sequences.toSorted(\n (first, second) => second.length - first.length,\n )) {\n const sequence = backward ? source.toReversed() : source;\n let node = root;\n for (const character of sequence) {\n const child: ClassStringTrie = node.children.get(character) ?? {\n children: new Map(),\n terminal: false,\n };\n node.children.set(character, child);\n node = child;\n }\n node.terminal = true;\n }\n return root;\n}\n\nfunction emitClassAlternatives(\n builder: Builder,\n branches: readonly (() => void)[],\n span: RegExpSpan,\n): void {\n if (branches.length === 0) return;\n const end = newLabel(builder);\n for (const [index, branch] of branches.entries()) {\n if (index + 1 === branches.length) {\n branch();\n break;\n }\n const preferred = newLabel(builder);\n const next = newLabel(builder);\n emit(builder, { alternative: next, kind: \"fork\", preferred }, span);\n placeLabel(builder, preferred);\n branch();\n emit(builder, { kind: \"jump\", target: end }, span);\n placeLabel(builder, next);\n }\n placeLabel(builder, end);\n}\n\n/**\n * One pending step of the iterative class-string trie emission.\n *\n * A trie is as deep as its longest string, so emitting it through host\n * recursion would spend one frame per code point and exhaust the stack on a\n * `\\q{...}` alternative that the reviewed source and instruction limits both\n * admit. These steps carry that work on the heap instead, and the emitter\n * pops them in the order the equivalent recursion ran, so one pattern still\n * compiles to exactly the same instructions and labels.\n */\ntype ClassStringStep =\n | {\n readonly end: number;\n readonly entries: readonly (readonly [number, ClassStringTrie])[];\n readonly index: number;\n readonly kind: \"branch\";\n readonly terminal: boolean;\n }\n | { readonly character: number; readonly kind: \"consume\" }\n | {\n readonly jump: number | undefined;\n readonly kind: \"finish\";\n readonly label: number;\n }\n | { readonly kind: \"node\"; readonly node: ClassStringTrie };\n\nfunction emitClassStringTrie(\n builder: Builder,\n root: ClassStringTrie,\n backward: boolean,\n span: RegExpSpan,\n): void {\n const steps: ClassStringStep[] = [{ kind: \"node\", node: root }];\n for (;;) {\n const step = steps.pop();\n if (step == null) return;\n if (step.kind === \"consume\") {\n emitClassValueBranch(builder, [step.character], false, backward, span);\n continue;\n }\n if (step.kind === \"finish\") {\n if (step.jump != null) {\n emit(builder, { kind: \"jump\", target: step.jump }, span);\n }\n placeLabel(builder, step.label);\n continue;\n }\n if (step.kind === \"node\") {\n const entries = [...step.node.children];\n const terminal = step.node.terminal;\n if (entries.length === 0 && !terminal) continue;\n steps.push({\n end: newLabel(builder),\n entries,\n index: 0,\n kind: \"branch\",\n terminal,\n });\n continue;\n }\n const { end, entries, index, terminal } = step;\n if (index + 1 === entries.length + (terminal ? 1 : 0)) {\n steps.push({ jump: undefined, kind: \"finish\", label: end });\n } else {\n const preferred = newLabel(builder);\n const next = newLabel(builder);\n emit(builder, { alternative: next, kind: \"fork\", preferred }, span);\n placeLabel(builder, preferred);\n steps.push({ ...step, index: index + 1 });\n steps.push({ jump: end, kind: \"finish\", label: next });\n }\n const entry = entries[index];\n if (entry != null) {\n steps.push({ kind: \"node\", node: entry[1] });\n steps.push({ character: entry[0], kind: \"consume\" });\n }\n }\n}\n\nfunction buildClassValue(\n builder: Builder,\n value: ClassValue,\n backward: boolean,\n span: RegExpSpan,\n): void {\n if (value.strings.length === 0 && value.characters.length === 0) {\n emitClassValueBranch(builder, [], true, backward, span);\n return;\n }\n const branches: (() => void)[] = [];\n const nonEmptyStrings = value.strings.filter(\n (sequence) => sequence.length > 0,\n );\n if (nonEmptyStrings.length > 0) {\n const trie = classStringTrie(nonEmptyStrings, backward);\n branches.push(() => emitClassStringTrie(builder, trie, backward, span));\n }\n if (value.characters.length > 0) {\n branches.push(() =>\n emitClassValueBranch(builder, value.characters, true, backward, span),\n );\n }\n if (value.strings.some((sequence) => sequence.length === 0)) {\n branches.push(() => undefined);\n }\n emitClassAlternatives(builder, branches, span);\n}\n\n/** The lowest and highest capture index one atom encloses. */\nfunction captureBounds(\n atom: RegExpAtom,\n): readonly [number, number] | undefined {\n let first: number | undefined;\n let last: number | undefined;\n const note = (index: number): void => {\n first = first == null ? index : Math.min(first, index);\n last = last == null ? index : Math.max(last, index);\n };\n const visitDisjunction = (node: RegExpDisjunction): void => {\n for (const alternative of node.alternatives) {\n for (const term of alternative.terms) visitTerm(term);\n }\n };\n const visitAtom = (node: RegExpAtom): void => {\n if (node.kind === \"capturing-group\") {\n note(node.index);\n visitDisjunction(node.body);\n return;\n }\n if (node.kind === \"group\" || node.kind === \"modifier-group\") {\n visitDisjunction(node.body);\n }\n };\n const visitTerm = (term: RegExpTerm): void => {\n if (term.kind === \"assertion\") return;\n if (term.kind === \"lookaround\") {\n visitDisjunction(term.body);\n return;\n }\n visitAtom(term.kind === \"quantified\" ? term.atom : term);\n };\n visitAtom(atom);\n if (first == null || last == null) return undefined;\n return [first, last];\n}\n\nfunction buildAtom(\n builder: Builder,\n atom: RegExpAtom,\n backward: boolean,\n): void {\n const set = characterAtomSet(builder, atom);\n if (set != null) {\n emit(\n builder,\n { backward, kind: \"consume\", set: internSet(builder, set) },\n atom.span,\n );\n return;\n }\n if (atom.kind === \"class-set\") {\n buildClassValue(builder, classSetValue(builder, atom), backward, atom.span);\n return;\n }\n if (atom.kind === \"unicode-property\") {\n buildClassValue(\n builder,\n propertyEscapeClassValue(builder, atom),\n backward,\n atom.span,\n );\n return;\n }\n if (atom.kind === \"capturing-group\") {\n const start = 2 * atom.index;\n const end = start + 1;\n emit(builder, { kind: \"save\", slot: backward ? end : start }, atom.span);\n buildDisjunction(builder, atom.body, backward);\n emit(builder, { kind: \"save\", slot: backward ? start : end }, atom.span);\n return;\n }\n if (atom.kind === \"group\") {\n buildDisjunction(builder, atom.body, backward);\n return;\n }\n if (atom.kind === \"modifier-group\") {\n const dotAll = builder.dotAll;\n const ignoreCase = builder.ignoreCase;\n const multiline = builder.multiline;\n builder.dotAll =\n atom.enabled.includes(\"s\") || (dotAll && !atom.disabled.includes(\"s\"));\n builder.ignoreCase =\n atom.enabled.includes(\"i\") ||\n (ignoreCase && !atom.disabled.includes(\"i\"));\n builder.multiline =\n atom.enabled.includes(\"m\") || (multiline && !atom.disabled.includes(\"m\"));\n buildDisjunction(builder, atom.body, backward);\n builder.dotAll = dotAll;\n builder.ignoreCase = ignoreCase;\n builder.multiline = multiline;\n return;\n }\n if (atom.kind === \"backreference\" || atom.kind === \"named-backreference\") {\n const slots =\n atom.kind === \"backreference\"\n ? [2 * atom.index]\n : atom.indices.map((index: number) => 2 * index);\n emit(\n builder,\n {\n backward,\n ignoreCase: builder.ignoreCase,\n kind: \"backreference\",\n slots,\n },\n atom.span,\n );\n return;\n }\n refuse(\n \"unsupported\",\n \"This pattern atom has no matcher lowering yet.\",\n atom.span,\n );\n}\n\nfunction buildQuantified(\n builder: Builder,\n term: RegExpQuantified,\n backward: boolean,\n): void {\n const counter = allocateRegisters(builder, 2, term.span);\n const position = counter + 1;\n const bounds = captureBounds(term.atom);\n const head = newLabel(builder);\n const enter = newLabel(builder);\n const body = newLabel(builder);\n const exit = newLabel(builder);\n emit(builder, { counter, kind: \"repeat-init\" }, term.span);\n placeLabel(builder, head);\n emit(\n builder,\n {\n counter,\n enter,\n exit,\n greedy: term.quantifier.greedy,\n kind: \"repeat\",\n maximum: term.quantifier.maximum,\n minimum: term.quantifier.minimum,\n },\n term.span,\n );\n placeLabel(builder, enter);\n emit(\n builder,\n {\n body,\n clearFrom: bounds == null ? 0 : 2 * bounds[0],\n clearTo: bounds == null ? 0 : 2 * bounds[1] + 2,\n counter,\n kind: \"repeat-enter\",\n position,\n },\n term.span,\n );\n placeLabel(builder, body);\n buildAtom(builder, term.atom, backward);\n emit(\n builder,\n {\n counter,\n head,\n kind: \"repeat-end\",\n minimum: term.quantifier.minimum,\n position,\n },\n term.span,\n );\n placeLabel(builder, exit);\n}\n\nfunction buildAssertion(builder: Builder, term: RegExpEdgeAssertion): void {\n if (term.assertion === \"start\" || term.assertion === \"end\") {\n emit(\n builder,\n { assertion: term.assertion, kind: \"edge\", multiline: builder.multiline },\n term.span,\n );\n return;\n }\n const set =\n builder.wordSets.get(builder.ignoreCase) ??\n internSet(builder, wordCharacters(builder, term.span));\n builder.wordSets.set(builder.ignoreCase, set);\n emit(\n builder,\n {\n kind: \"boundary\",\n negated: term.assertion === \"non-word-boundary\",\n set,\n },\n term.span,\n );\n}\n\nfunction buildLookaround(builder: Builder, term: RegExpLookaround): void {\n const frame = allocateRegisters(builder, 1, term.span);\n const body = newLabel(builder);\n const exit = newLabel(builder);\n emit(\n builder,\n {\n body,\n frame,\n kind: \"look-start\",\n negated: term.negated,\n onFail: term.negated ? exit : builder.failLabel,\n },\n term.span,\n );\n placeLabel(builder, body);\n buildDisjunction(builder, term.body, term.direction === \"behind\");\n emit(\n builder,\n { exit, frame, kind: \"look-end\", negated: term.negated },\n term.span,\n );\n placeLabel(builder, exit);\n}\n\nfunction buildTerm(\n builder: Builder,\n term: RegExpTerm,\n backward: boolean,\n): void {\n if (term.kind === \"assertion\") {\n buildAssertion(builder, term);\n return;\n }\n if (term.kind === \"lookaround\") {\n buildLookaround(builder, term);\n return;\n }\n if (term.kind === \"quantified\") {\n buildQuantified(builder, term, backward);\n return;\n }\n buildAtom(builder, term, backward);\n}\n\n/**\n * Emit one alternative in evaluation order.\n *\n * A backward alternative evaluates its rightmost term first, which is what\n * makes a lookbehind body read toward the start of the input.\n */\nfunction buildAlternative(\n builder: Builder,\n alternative: RegExpAlternative,\n backward: boolean,\n): void {\n const terms = backward ? alternative.terms.toReversed() : alternative.terms;\n for (const term of terms) buildTerm(builder, term, backward);\n}\n\nfunction buildDisjunction(\n builder: Builder,\n disjunction: RegExpDisjunction,\n backward: boolean,\n): void {\n const alternatives = disjunction.alternatives;\n const last = alternatives.length - 1;\n if (last === 0) {\n const only = alternatives[0];\n if (only != null) buildAlternative(builder, only, backward);\n return;\n }\n const end = newLabel(builder);\n for (const [index, alternative] of alternatives.entries()) {\n if (index === last) {\n buildAlternative(builder, alternative, backward);\n break;\n }\n const preferred = newLabel(builder);\n const next = newLabel(builder);\n emit(\n builder,\n { alternative: next, kind: \"fork\", preferred },\n alternative.span,\n );\n placeLabel(builder, preferred);\n buildAlternative(builder, alternative, backward);\n emit(builder, { kind: \"jump\", target: end }, alternative.span);\n placeLabel(builder, next);\n }\n placeLabel(builder, end);\n}\n\n/** Rewrite every label reference into the address it was placed at. */\nfunction resolveTargets(\n instruction: RegExpMatcherInstruction,\n addresses: readonly number[],\n): RegExpMatcherInstruction {\n const address = (label: number): number => addresses[label] ?? 0;\n if (instruction.kind === \"fork\") {\n return {\n alternative: address(instruction.alternative),\n kind: \"fork\",\n preferred: address(instruction.preferred),\n };\n }\n if (instruction.kind === \"jump\") {\n return { kind: \"jump\", target: address(instruction.target) };\n }\n if (instruction.kind === \"repeat\") {\n return {\n ...instruction,\n enter: address(instruction.enter),\n exit: address(instruction.exit),\n };\n }\n if (instruction.kind === \"repeat-enter\") {\n return { ...instruction, body: address(instruction.body) };\n }\n if (instruction.kind === \"repeat-end\") {\n return { ...instruction, head: address(instruction.head) };\n }\n if (instruction.kind === \"look-start\") {\n return {\n ...instruction,\n body: address(instruction.body),\n onFail: address(instruction.onFail),\n };\n }\n if (instruction.kind === \"look-end\") {\n return { ...instruction, exit: address(instruction.exit) };\n }\n return instruction;\n}\n\n/** Record every character whose canonical form is another character. */\nfunction canonicalizationTable(\n classes: readonly (readonly number[])[],\n): RegExpMatcherCanonicalization {\n const pairs: (readonly [number, number])[] = [];\n for (const members of classes) {\n if (members.length < 2) continue;\n const representative = members.reduce(\n (lowest, member) => Math.min(lowest, member),\n members[0] ?? 0,\n );\n for (const member of members) {\n if (member !== representative) pairs.push([member, representative]);\n }\n }\n const sorted = pairs.toSorted((first, second) => first[0] - second[0]);\n return {\n canonical: sorted.map(([, canonical]) => canonical),\n characters: sorted.map(([character]) => character),\n };\n}\n\n/** Whether one artifact compares two input characters under `i`. */\nfunction comparesCharacters(\n instructions: readonly RegExpMatcherInstruction[],\n): boolean {\n return instructions.some(\n (instruction) =>\n instruction.kind === \"backreference\" && instruction.ignoreCase,\n );\n}\n\n/**\n * Copy the pattern metadata one artifact keeps.\n *\n * An artifact must not alias a value its caller still owns. Freezing the\n * caller's arrays would change the pattern the caller passed in, and\n * sharing them would let a later write to that pattern change how the\n * artifact matches, which is the whole of the immutability contract.\n */\nfunction ownedFlags(flags: RegExpFlags): RegExpFlags {\n return Object.freeze({\n dotAll: flags.dotAll,\n global: flags.global,\n hasIndices: flags.hasIndices,\n ignoreCase: flags.ignoreCase,\n multiline: flags.multiline,\n sticky: flags.sticky,\n text: flags.text,\n unicode: flags.unicode,\n unicodeSets: flags.unicodeSets,\n });\n}\n\nfunction ownedCaptures(\n captures: readonly RegExpCapture[],\n): readonly RegExpCapture[] {\n return Object.freeze(\n captures.map((capture) =>\n Object.freeze({\n index: capture.index,\n span: Object.freeze({\n end: capture.span.end,\n start: capture.span.start,\n }),\n ...includePropertiesWhen(() => {\n if (capture.name == null) return undefined;\n return { name: capture.name };\n }),\n }),\n ),\n );\n}\n\nfunction freezeProgram(program: RegExpMatcherProgram): RegExpMatcherProgram {\n for (const instruction of program.instructions) {\n if (instruction.kind === \"backreference\") Object.freeze(instruction.slots);\n Object.freeze(instruction);\n }\n Object.freeze(program.sets);\n Object.freeze(program.instructions);\n const table = program.canonicalization;\n if (table != null) {\n Object.freeze(table.canonical);\n Object.freeze(table.characters);\n Object.freeze(table);\n }\n return Object.freeze(program);\n}\n\n/**\n * Build the generic matcher artifact of one validated pattern.\n *\n * Every construct the pattern parser admits either compiles to defined\n * behavior here or is refused with a located error. Nothing is\n * approximated: a construct whose matcher semantics this unit does not own\n * and a Unicode fact its caller did not supply both stop the build rather\n * than producing an artifact that matches something else.\n */\nexport function buildRegExpMatcher(\n pattern: RegExpPattern,\n options: RegExpMatcherOptions = {},\n): RegExpMatcherResult {\n const limits = options.limits ?? defaultRegExpMatcherLimits;\n checkRegExpMatcherBound(limits.instructions, \"An instruction limit\");\n checkRegExpMatcherBound(limits.registers, \"A register limit\");\n const flags = pattern.flags;\n const builder: Builder = {\n addresses: [unplacedLabel],\n caseRepresentatives: undefined,\n classes: undefined,\n dotAll: flags.dotAll,\n failLabel: 0,\n ignoreCase: flags.ignoreCase,\n instructions: [],\n limits,\n lowered: 0,\n multiline: flags.multiline,\n registers: 2 * (pattern.captures.length + 1),\n setIndices: new Map(),\n sets: [],\n unicodeData: options.unicodeData ?? {},\n unicodeMode: regExpUnicodeMode(flags),\n unicodeSets: flags.unicodeSets,\n wordSets: new Map(),\n };\n const whole: RegExpSpan = { end: pattern.source.length, start: 0 };\n try {\n if (builder.registers > limits.registers) {\n refuse(\n \"limit\",\n \"A pattern needs more matcher registers than the reviewed limit.\",\n whole,\n );\n }\n emit(builder, { kind: \"save\", slot: 0 }, whole);\n buildDisjunction(builder, pattern.body, false);\n emit(builder, { kind: \"save\", slot: 1 }, whole);\n emit(builder, { kind: \"accept\" }, whole);\n placeLabel(builder, builder.failLabel);\n emit(builder, { kind: \"fail\" }, whole);\n const instructions = builder.instructions.map((instruction) =>\n resolveTargets(instruction, builder.addresses),\n );\n const program: RegExpMatcherProgram = {\n captures: ownedCaptures(pattern.captures),\n flags: ownedFlags(flags),\n groupNames: Object.freeze([...pattern.groupNames]),\n instructions,\n kind: \"matcher\",\n registers: builder.registers,\n sets: builder.sets,\n source: pattern.source,\n unicodeMode: builder.unicodeMode,\n ...includePropertiesWhen(() => {\n if (!comparesCharacters(instructions)) return undefined;\n return {\n canonicalization: canonicalizationTable(caseClasses(builder, whole)),\n };\n }),\n };\n return { built: true, errors: [], program: freezeProgram(program) };\n } catch (error) {\n if (error instanceof MatcherFailure) {\n return { built: false, errors: [error.error] };\n }\n throw error;\n }\n}\n"],"mappings":";;;AAwCA,SAAS,sBACP,YACoD;CACpD,OAAO,WAAW,KAAK,CAAC;AAC1B;;AAGA,MAAM,mBAAmB;;AAGzB,MAAM,iBAAiB;;AAmBvB,SAAS,OAAO,KAAuB,WAA4B;CACjE,IAAI,MAAM;CACV,IAAI,OAAO,IAAI;CACf,OAAO,MAAM,MAAM;EACjB,MAAM,SAAU,MAAM,QAAS;EAC/B,KAAK,IAAI,WAAW,MAAM,WAAW,MAAM,SAAS;OAC/C,OAAO;CACd;CACA,QAAQ,MAAM,OAAO;AACvB;;AAGA,SAAS,WAAW,OAAe,KAA+B;CAChE,OAAO,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC;AAC3C;;AAGA,SAAS,SACP,MACA,OACkB;CAClB,MAAM,aAAuB,CAAC;CAC9B,IAAI,YAAY;CAChB,IAAI,aAAa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EACL,kBAAkB,sBAAsB,YAAY,SAAS,KAAK,CAAC,EACrE;IACF,CAAC;GAE4D,CAAC;EAAE;CACpE,SAAS,OAAO;EACd,IAAI,iBAAiB,gBACnB,OAAO;GAAE,OAAO;GAAO,QAAQ,CAAC,MAAM,KAAK;EAAE;EAE/C,MAAM;CACR;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexp-parse.d.ts","names":[],"sources":["../src/regexp-parse.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"regexp-parse.d.ts","names":[],"sources":["../src/regexp-parse.ts"],"mappings":";;;;;;;;;;iBAo7DgB,mBACd,OAAO,qBACN;;;;;;;;iBA0Ea,mBACd,SAAS,qBACT,UAAS,uBACR"}
|