@oseo/compiler 0.0.0-stage → 0.1.0-canary.0
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/LICENSE +674 -0
- package/README.md +172 -2
- package/dist/agent-programs.d.ts +28 -0
- package/dist/agent-programs.d.ts.map +1 -0
- package/dist/agent-programs.js +134 -0
- package/dist/agent-programs.js.map +1 -0
- package/dist/agent-templates.d.ts +33 -0
- package/dist/agent-templates.d.ts.map +1 -0
- package/dist/agent-templates.js +45 -0
- package/dist/agent-templates.js.map +1 -0
- package/dist/compile.d.ts +20 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +75 -0
- package/dist/compile.js.map +1 -0
- package/dist/fragments.d.ts +72 -0
- package/dist/fragments.d.ts.map +1 -0
- package/dist/fragments.js +158 -0
- package/dist/fragments.js.map +1 -0
- package/dist/hir-build.d.ts +80 -0
- package/dist/hir-build.d.ts.map +1 -0
- package/dist/hir-build.js +3077 -0
- package/dist/hir-build.js.map +1 -0
- package/dist/hir-print.d.ts +10 -0
- package/dist/hir-print.d.ts.map +1 -0
- package/dist/hir-print.js +271 -0
- package/dist/hir-print.js.map +1 -0
- package/dist/hir.d.ts +1246 -0
- package/dist/hir.d.ts.map +1 -0
- package/dist/hir.js +147 -0
- package/dist/hir.js.map +1 -0
- package/dist/host-scripts.d.ts +14 -0
- package/dist/host-scripts.d.ts.map +1 -0
- package/dist/host-scripts.js +204 -0
- package/dist/host-scripts.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/mir-build.d.ts +8 -0
- package/dist/mir-build.d.ts.map +1 -0
- package/dist/mir-build.js +5113 -0
- package/dist/mir-build.js.map +1 -0
- package/dist/mir-print.d.ts +7 -0
- package/dist/mir-print.d.ts.map +1 -0
- package/dist/mir-print.js +65 -0
- package/dist/mir-print.js.map +1 -0
- package/dist/mir-specialize.d.ts +7 -0
- package/dist/mir-specialize.d.ts.map +1 -0
- package/dist/mir-specialize.js +182 -0
- package/dist/mir-specialize.js.map +1 -0
- package/dist/mir.d.ts +571 -0
- package/dist/mir.d.ts.map +1 -0
- package/dist/mir.js +1 -0
- package/dist/module-builtin.d.ts +20 -0
- package/dist/module-builtin.d.ts.map +1 -0
- package/dist/module-builtin.js +57 -0
- package/dist/module-builtin.js.map +1 -0
- package/dist/module-compile.d.ts +64 -0
- package/dist/module-compile.d.ts.map +1 -0
- package/dist/module-compile.js +690 -0
- package/dist/module-compile.js.map +1 -0
- package/dist/module-json.d.ts +7 -0
- package/dist/module-json.d.ts.map +1 -0
- package/dist/module-json.js +88 -0
- package/dist/module-json.js.map +1 -0
- package/dist/modules.d.ts +87 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +734 -0
- package/dist/modules.js.map +1 -0
- package/dist/native-fragments.d.ts +36 -0
- package/dist/native-fragments.d.ts.map +1 -0
- package/dist/native-fragments.js +110 -0
- package/dist/native-fragments.js.map +1 -0
- package/dist/native.d.ts +282 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +47 -0
- package/dist/native.js.map +1 -0
- package/dist/regexp-execute.d.ts +74 -0
- package/dist/regexp-execute.d.ts.map +1 -0
- package/dist/regexp-execute.js +480 -0
- package/dist/regexp-execute.js.map +1 -0
- package/dist/regexp-matcher.d.ts +279 -0
- package/dist/regexp-matcher.d.ts.map +1 -0
- package/dist/regexp-matcher.js +1098 -0
- package/dist/regexp-matcher.js.map +1 -0
- package/dist/regexp-parse.d.ts +22 -0
- package/dist/regexp-parse.d.ts.map +1 -0
- package/dist/regexp-parse.js +1440 -0
- package/dist/regexp-parse.js.map +1 -0
- package/dist/regexp-print.d.ts +24 -0
- package/dist/regexp-print.d.ts.map +1 -0
- package/dist/regexp-print.js +147 -0
- package/dist/regexp-print.js.map +1 -0
- package/dist/regexp.d.ts +324 -0
- package/dist/regexp.d.ts.map +1 -0
- package/dist/regexp.js +22 -0
- package/dist/regexp.js.map +1 -0
- package/dist/source.d.ts +38 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +10 -0
- package/dist/source.js.map +1 -0
- package/dist/syntax.d.ts +1232 -0
- package/dist/syntax.d.ts.map +1 -0
- package/dist/syntax.js +1 -0
- package/package.json +32 -3
|
@@ -0,0 +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,SAAW,Q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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"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { RegExpCapture, RegExpFlags, RegExpPattern, RegExpPatternError, RegExpUnicodePropertyEscape } from "./regexp.js";
|
|
2
|
+
//#region src/regexp-matcher.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* One immutable character set as an inversion list.
|
|
5
|
+
*
|
|
6
|
+
* The list is a strictly increasing, even-length array of boundaries where
|
|
7
|
+
* membership toggles, so `[0x41, 0x5b]` is U+0041 through U+005A. A closing
|
|
8
|
+
* boundary may equal one past the largest code point, which is the only
|
|
9
|
+
* value the list may hold that is not itself a code point.
|
|
10
|
+
*
|
|
11
|
+
* `@oseo/unicode` publishes its tables in exactly this shape, so a table
|
|
12
|
+
* reaches an artifact without being reshaped. The compiler core links no
|
|
13
|
+
* Unicode data, so the few set operations the builder needs are implemented
|
|
14
|
+
* here rather than imported: the dependency direction, not the duplication,
|
|
15
|
+
* is what the package boundary protects.
|
|
16
|
+
*/
|
|
17
|
+
type RegExpMatcherSet = readonly number[];
|
|
18
|
+
/**
|
|
19
|
+
* One code point that canonicalizes to another, recorded for execution.
|
|
20
|
+
*
|
|
21
|
+
* `characters` is strictly increasing and `canonical` holds the canonical
|
|
22
|
+
* form of the character at the same offset. A character the table omits
|
|
23
|
+
* canonicalizes to itself. The executor needs this only where a
|
|
24
|
+
* backreference compares two input characters under `i`; every other
|
|
25
|
+
* ignore-case decision is folded into a set while the artifact is built.
|
|
26
|
+
*/
|
|
27
|
+
interface RegExpMatcherCanonicalization {
|
|
28
|
+
readonly canonical: readonly number[];
|
|
29
|
+
readonly characters: readonly number[];
|
|
30
|
+
}
|
|
31
|
+
/** Consume one character of the input in the instruction's direction. */
|
|
32
|
+
interface RegExpMatcherConsume {
|
|
33
|
+
readonly backward: boolean;
|
|
34
|
+
readonly kind: "consume";
|
|
35
|
+
readonly set: number;
|
|
36
|
+
}
|
|
37
|
+
/** Assert `^` or `$` at the current position. */
|
|
38
|
+
interface RegExpMatcherEdge {
|
|
39
|
+
readonly assertion: "end" | "start";
|
|
40
|
+
readonly kind: "edge";
|
|
41
|
+
readonly multiline: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** Assert `\b` or `\B` at the current position. */
|
|
44
|
+
interface RegExpMatcherBoundary {
|
|
45
|
+
readonly kind: "boundary";
|
|
46
|
+
readonly negated: boolean;
|
|
47
|
+
readonly set: number;
|
|
48
|
+
}
|
|
49
|
+
/** Record the current position in one capture register. */
|
|
50
|
+
interface RegExpMatcherSave {
|
|
51
|
+
readonly kind: "save";
|
|
52
|
+
readonly slot: number;
|
|
53
|
+
}
|
|
54
|
+
/** Reset a contiguous capture register range to unset. */
|
|
55
|
+
interface RegExpMatcherClear {
|
|
56
|
+
readonly from: number;
|
|
57
|
+
readonly kind: "clear";
|
|
58
|
+
readonly to: number;
|
|
59
|
+
}
|
|
60
|
+
/** Try one continuation first and keep the other for backtracking. */
|
|
61
|
+
interface RegExpMatcherFork {
|
|
62
|
+
readonly alternative: number;
|
|
63
|
+
readonly kind: "fork";
|
|
64
|
+
readonly preferred: number;
|
|
65
|
+
}
|
|
66
|
+
/** Continue at one address. */
|
|
67
|
+
interface RegExpMatcherJump {
|
|
68
|
+
readonly kind: "jump";
|
|
69
|
+
readonly target: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Decide whether one repetition iterates again.
|
|
73
|
+
*
|
|
74
|
+
* Below `minimum` the iteration is forced, at `maximum` the repetition
|
|
75
|
+
* exits, and between them `greedy` orders the two continuations. The
|
|
76
|
+
* decision never inspects the input, so a repetition is one loop in the
|
|
77
|
+
* artifact whatever its bounds say.
|
|
78
|
+
*/
|
|
79
|
+
interface RegExpMatcherRepeat {
|
|
80
|
+
readonly counter: number;
|
|
81
|
+
readonly enter: number;
|
|
82
|
+
readonly exit: number;
|
|
83
|
+
readonly greedy: boolean;
|
|
84
|
+
readonly kind: "repeat";
|
|
85
|
+
readonly maximum: number;
|
|
86
|
+
readonly minimum: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Begin one repetition, discarding the count of any earlier entry.
|
|
90
|
+
*
|
|
91
|
+
* The edition gives every entry into a quantified atom a fresh repetition
|
|
92
|
+
* state, so a repetition nested in another one starts over each time the
|
|
93
|
+
* outer body runs rather than resuming the count it left behind.
|
|
94
|
+
*/
|
|
95
|
+
interface RegExpMatcherRepeatInit {
|
|
96
|
+
readonly counter: number;
|
|
97
|
+
readonly kind: "repeat-init";
|
|
98
|
+
}
|
|
99
|
+
/** Start one repetition iteration, clearing the captures it may set. */
|
|
100
|
+
interface RegExpMatcherRepeatEnter {
|
|
101
|
+
readonly body: number;
|
|
102
|
+
readonly clearFrom: number;
|
|
103
|
+
readonly clearTo: number;
|
|
104
|
+
readonly counter: number;
|
|
105
|
+
readonly kind: "repeat-enter";
|
|
106
|
+
readonly position: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Finish one repetition iteration.
|
|
110
|
+
*
|
|
111
|
+
* An iteration that consumed nothing fails once the repetition has met its
|
|
112
|
+
* lower bound, which is what stops an empty body from repeating forever
|
|
113
|
+
* while still letting the bound itself be satisfied by empty iterations.
|
|
114
|
+
*/
|
|
115
|
+
interface RegExpMatcherRepeatEnd {
|
|
116
|
+
readonly counter: number;
|
|
117
|
+
readonly head: number;
|
|
118
|
+
readonly kind: "repeat-end";
|
|
119
|
+
readonly minimum: number;
|
|
120
|
+
readonly position: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Enter one lookaround body.
|
|
124
|
+
*
|
|
125
|
+
* The instruction records the backtrack height its body may not unwind
|
|
126
|
+
* past, so the body's own choices are discarded when it finishes.
|
|
127
|
+
* `onFail` is where the assertion continues once its body has no match
|
|
128
|
+
* left: the shared failure instruction for a positive assertion, and the
|
|
129
|
+
* instruction after the assertion for a negative one, which is the only
|
|
130
|
+
* way a negative assertion succeeds.
|
|
131
|
+
*/
|
|
132
|
+
interface RegExpMatcherLookStart {
|
|
133
|
+
readonly body: number;
|
|
134
|
+
readonly frame: number;
|
|
135
|
+
readonly kind: "look-start";
|
|
136
|
+
readonly negated: boolean;
|
|
137
|
+
readonly onFail: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Leave one lookaround body that matched.
|
|
141
|
+
*
|
|
142
|
+
* A positive assertion restores the entry position, keeps the captures the
|
|
143
|
+
* body set, and discards the body's remaining choices. A negative
|
|
144
|
+
* assertion undoes both and fails.
|
|
145
|
+
*/
|
|
146
|
+
interface RegExpMatcherLookEnd {
|
|
147
|
+
readonly exit: number;
|
|
148
|
+
readonly frame: number;
|
|
149
|
+
readonly kind: "look-end";
|
|
150
|
+
readonly negated: boolean;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Match the text one earlier capture holds.
|
|
154
|
+
*
|
|
155
|
+
* `slots` names every capture a group name resolves to, in ascending
|
|
156
|
+
* index order. At most one of them can have participated in the match, and
|
|
157
|
+
* a reference to a capture that did not participate matches the empty
|
|
158
|
+
* string rather than failing.
|
|
159
|
+
*/
|
|
160
|
+
interface RegExpMatcherBackreference {
|
|
161
|
+
readonly backward: boolean;
|
|
162
|
+
readonly ignoreCase: boolean;
|
|
163
|
+
readonly kind: "backreference";
|
|
164
|
+
readonly slots: readonly number[];
|
|
165
|
+
}
|
|
166
|
+
/** Report the whole pattern as matched. */
|
|
167
|
+
interface RegExpMatcherAccept {
|
|
168
|
+
readonly kind: "accept";
|
|
169
|
+
}
|
|
170
|
+
/** Abandon the current path and backtrack. */
|
|
171
|
+
interface RegExpMatcherFail {
|
|
172
|
+
readonly kind: "fail";
|
|
173
|
+
}
|
|
174
|
+
/** One instruction of a matcher artifact. */
|
|
175
|
+
type RegExpMatcherInstruction = RegExpMatcherAccept | RegExpMatcherBackreference | RegExpMatcherBoundary | RegExpMatcherClear | RegExpMatcherConsume | RegExpMatcherEdge | RegExpMatcherFail | RegExpMatcherFork | RegExpMatcherJump | RegExpMatcherLookEnd | RegExpMatcherLookStart | RegExpMatcherRepeat | RegExpMatcherRepeatEnd | RegExpMatcherRepeatEnter | RegExpMatcherRepeatInit | RegExpMatcherSave;
|
|
176
|
+
/**
|
|
177
|
+
* One immutable matcher artifact.
|
|
178
|
+
*
|
|
179
|
+
* The artifact is the semantic authority for one pattern: an ahead-of-time
|
|
180
|
+
* lowering and any later fast path must produce the match state this
|
|
181
|
+
* program produces. It holds no mutable field and no reference to a
|
|
182
|
+
* regular expression object, so equal artifacts may be shared while every
|
|
183
|
+
* evaluation still owns its own object identity and `lastIndex`.
|
|
184
|
+
*
|
|
185
|
+
* Register 0 and 1 hold the whole match, and registers `2 * index` and
|
|
186
|
+
* `2 * index + 1` hold capturing group `index`. The remaining registers
|
|
187
|
+
* are repetition counters, repetition positions, and lookaround frames.
|
|
188
|
+
*/
|
|
189
|
+
interface RegExpMatcherProgram {
|
|
190
|
+
readonly canonicalization?: RegExpMatcherCanonicalization;
|
|
191
|
+
readonly captures: readonly RegExpCapture[];
|
|
192
|
+
readonly flags: RegExpFlags;
|
|
193
|
+
readonly groupNames: readonly string[];
|
|
194
|
+
readonly instructions: readonly RegExpMatcherInstruction[];
|
|
195
|
+
readonly kind: "matcher";
|
|
196
|
+
readonly registers: number;
|
|
197
|
+
readonly sets: readonly RegExpMatcherSet[];
|
|
198
|
+
readonly source: string;
|
|
199
|
+
readonly unicodeMode: boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Unicode facts the builder cannot derive on its own.
|
|
203
|
+
*
|
|
204
|
+
* The compiler core links no Unicode data, so a caller that owns the
|
|
205
|
+
* pinned tables supplies the raw facts and the builder owns every
|
|
206
|
+
* ECMAScript decision made from them. A pattern whose grammar needs a fact
|
|
207
|
+
* the caller did not supply is refused with a located error rather than
|
|
208
|
+
* matched against a guess.
|
|
209
|
+
*
|
|
210
|
+
* `caseEquivalenceClasses` returns every class of two or more characters
|
|
211
|
+
* that `Canonicalize` maps together for the given mode, which is simple
|
|
212
|
+
* case folding under `u` or `v` and the single-code-unit uppercase rule
|
|
213
|
+
* otherwise. Classes of one character are omitted because they change
|
|
214
|
+
* nothing.
|
|
215
|
+
*/
|
|
216
|
+
interface RegExpMatcherUnicodeData {
|
|
217
|
+
readonly caseEquivalenceClasses?: (unicodeMode: boolean) => readonly (readonly number[])[];
|
|
218
|
+
readonly propertySet?: (escape: RegExpUnicodePropertyEscape) => RegExpMatcherSet | undefined;
|
|
219
|
+
readonly stringPropertySet?: (escape: RegExpUnicodePropertyEscape) => readonly (readonly number[])[] | undefined;
|
|
220
|
+
readonly generalCategoryValue?: (name: string) => boolean;
|
|
221
|
+
readonly spaceSeparators?: RegExpMatcherSet;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Owned boundaries applied while one artifact is built.
|
|
225
|
+
*
|
|
226
|
+
* A pattern the parser already accepted stays within these for any
|
|
227
|
+
* ordinary source, so reaching one reports a located `limit` error rather
|
|
228
|
+
* than producing an artifact whose storage a later native lowering could
|
|
229
|
+
* not describe.
|
|
230
|
+
*/
|
|
231
|
+
interface RegExpMatcherLimits {
|
|
232
|
+
/**
|
|
233
|
+
* The lowered instruction count, which charges a backreference to a
|
|
234
|
+
* duplicated group name once per candidate capture because that is
|
|
235
|
+
* what a native encoding writes for it.
|
|
236
|
+
*/
|
|
237
|
+
readonly instructions: number;
|
|
238
|
+
readonly registers: number;
|
|
239
|
+
}
|
|
240
|
+
/** The reviewed default artifact limits. */
|
|
241
|
+
declare const defaultRegExpMatcherLimits: RegExpMatcherLimits;
|
|
242
|
+
/** Optional components of one artifact build. */
|
|
243
|
+
interface RegExpMatcherOptions {
|
|
244
|
+
readonly limits?: RegExpMatcherLimits;
|
|
245
|
+
readonly unicodeData?: RegExpMatcherUnicodeData;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The outcome of one build.
|
|
249
|
+
*
|
|
250
|
+
* `program` is present exactly when `built` is true, and `errors` is
|
|
251
|
+
* nonempty exactly when it is false.
|
|
252
|
+
*/
|
|
253
|
+
interface RegExpMatcherResult {
|
|
254
|
+
readonly built: boolean;
|
|
255
|
+
readonly errors: readonly RegExpPatternError[];
|
|
256
|
+
readonly program?: RegExpMatcherProgram;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Reject a boundary a caller supplied that is not a count.
|
|
260
|
+
*
|
|
261
|
+
* A limit that is not a nonnegative safe integer would silently disable
|
|
262
|
+
* the boundary it names, because every comparison against it is false.
|
|
263
|
+
* That is a caller defect rather than a pattern the unit cannot describe,
|
|
264
|
+
* so it throws instead of reporting a located pattern error.
|
|
265
|
+
*/
|
|
266
|
+
declare function checkRegExpMatcherBound(value: number, subject: string): void;
|
|
267
|
+
/**
|
|
268
|
+
* Build the generic matcher artifact of one validated pattern.
|
|
269
|
+
*
|
|
270
|
+
* Every construct the pattern parser admits either compiles to defined
|
|
271
|
+
* behavior here or is refused with a located error. Nothing is
|
|
272
|
+
* approximated: a construct whose matcher semantics this unit does not own
|
|
273
|
+
* and a Unicode fact its caller did not supply both stop the build rather
|
|
274
|
+
* than producing an artifact that matches something else.
|
|
275
|
+
*/
|
|
276
|
+
declare function buildRegExpMatcher(pattern: RegExpPattern, options?: RegExpMatcherOptions): RegExpMatcherResult;
|
|
277
|
+
//#endregion
|
|
278
|
+
export { RegExpMatcherAccept, RegExpMatcherBackreference, RegExpMatcherBoundary, RegExpMatcherCanonicalization, RegExpMatcherClear, RegExpMatcherConsume, RegExpMatcherEdge, RegExpMatcherFail, RegExpMatcherFork, RegExpMatcherInstruction, RegExpMatcherJump, RegExpMatcherLimits, RegExpMatcherLookEnd, RegExpMatcherLookStart, RegExpMatcherOptions, RegExpMatcherProgram, RegExpMatcherRepeat, RegExpMatcherRepeatEnd, RegExpMatcherRepeatEnter, RegExpMatcherRepeatInit, RegExpMatcherResult, RegExpMatcherSave, RegExpMatcherSet, RegExpMatcherUnicodeData, buildRegExpMatcher, checkRegExpMatcherBound, defaultRegExpMatcherLimits };
|
|
279
|
+
//# sourceMappingURL=regexp-matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexp-matcher.d.ts","names":[],"sources":["../src/regexp-matcher.ts"],"mappings":";;;;;;;;;;;;;;;;KAgDY;;;;;;;;;;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"}
|