@ac-kit/format-regex 0.2.7 → 0.3.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +89 -13
  3. package/dist/_iregexp-parse.d.ts +50 -0
  4. package/dist/_iregexp-parse.d.ts.map +1 -0
  5. package/dist/_iregexp-parse.js +367 -0
  6. package/dist/_iregexp-parse.js.map +1 -0
  7. package/dist/_unicode-category.d.ts +12 -0
  8. package/dist/_unicode-category.d.ts.map +1 -0
  9. package/dist/_unicode-category.js +49 -0
  10. package/dist/_unicode-category.js.map +1 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/iregexp-syntax-error.d.ts +13 -0
  16. package/dist/iregexp-syntax-error.d.ts.map +1 -0
  17. package/dist/iregexp-syntax-error.js +16 -0
  18. package/dist/iregexp-syntax-error.js.map +1 -0
  19. package/dist/iregexp.d.ts +91 -0
  20. package/dist/iregexp.d.ts.map +1 -0
  21. package/dist/iregexp.js +111 -0
  22. package/dist/iregexp.js.map +1 -0
  23. package/dist/limits.d.ts +25 -8
  24. package/dist/limits.d.ts.map +1 -1
  25. package/dist/limits.js +16 -6
  26. package/dist/limits.js.map +1 -1
  27. package/dist/parser.d.ts +16 -3
  28. package/dist/parser.d.ts.map +1 -1
  29. package/dist/parser.js +100 -66
  30. package/dist/parser.js.map +1 -1
  31. package/dist/printer.d.ts +12 -1
  32. package/dist/printer.d.ts.map +1 -1
  33. package/dist/printer.js +40 -21
  34. package/dist/printer.js.map +1 -1
  35. package/dist/regex.d.ts +43 -6
  36. package/dist/regex.d.ts.map +1 -1
  37. package/dist/regex.js +25 -10
  38. package/dist/regex.js.map +1 -1
  39. package/dist/vm/_class-predicate.d.ts +27 -0
  40. package/dist/vm/_class-predicate.d.ts.map +1 -0
  41. package/dist/vm/_class-predicate.js +65 -0
  42. package/dist/vm/_class-predicate.js.map +1 -0
  43. package/dist/vm/_thompson.d.ts +70 -0
  44. package/dist/vm/_thompson.d.ts.map +1 -0
  45. package/dist/vm/_thompson.js +196 -0
  46. package/dist/vm/_thompson.js.map +1 -0
  47. package/dist/vm/compile.d.ts +14 -2
  48. package/dist/vm/compile.d.ts.map +1 -1
  49. package/dist/vm/compile.js +83 -159
  50. package/dist/vm/compile.js.map +1 -1
  51. package/dist/vm/pike-vm.d.ts +38 -8
  52. package/dist/vm/pike-vm.d.ts.map +1 -1
  53. package/dist/vm/pike-vm.js +228 -102
  54. package/dist/vm/pike-vm.js.map +1 -1
  55. package/dist/vm/program.d.ts +29 -4
  56. package/dist/vm/program.d.ts.map +1 -1
  57. package/dist/walk.d.ts +7 -1
  58. package/dist/walk.d.ts.map +1 -1
  59. package/dist/walk.js +9 -3
  60. package/dist/walk.js.map +1 -1
  61. package/package.json +4 -3
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The general categories RFC 9485 §3 admits in `\p{…}` and `\P{…}`, each as a
3
+ * test of one code point.
4
+ *
5
+ * Literal patterns rather than `new RegExp(…)` over the name: the name in a
6
+ * pattern is only ever a key into this table, so no text from a pattern ever
7
+ * reaches the native regex compiler. Each test is anchored and sees exactly one
8
+ * code point, so it cannot backtrack. Membership follows the Unicode version of
9
+ * the JavaScript engine.
10
+ */
11
+ export declare const UNICODE_CATEGORY_TESTS_: ReadonlyMap<string, RegExp>;
12
+ //# sourceMappingURL=_unicode-category.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_unicode-category.d.ts","sourceRoot":"","sources":["../src/_unicode-category.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAqC9D,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The general categories RFC 9485 §3 admits in `\p{…}` and `\P{…}`, each as a
3
+ * test of one code point.
4
+ *
5
+ * Literal patterns rather than `new RegExp(…)` over the name: the name in a
6
+ * pattern is only ever a key into this table, so no text from a pattern ever
7
+ * reaches the native regex compiler. Each test is anchored and sees exactly one
8
+ * code point, so it cannot backtrack. Membership follows the Unicode version of
9
+ * the JavaScript engine.
10
+ */
11
+ export const UNICODE_CATEGORY_TESTS_ = new Map([
12
+ ["L", /^\p{L}$/u],
13
+ ["Ll", /^\p{Ll}$/u],
14
+ ["Lm", /^\p{Lm}$/u],
15
+ ["Lo", /^\p{Lo}$/u],
16
+ ["Lt", /^\p{Lt}$/u],
17
+ ["Lu", /^\p{Lu}$/u],
18
+ ["M", /^\p{M}$/u],
19
+ ["Mc", /^\p{Mc}$/u],
20
+ ["Me", /^\p{Me}$/u],
21
+ ["Mn", /^\p{Mn}$/u],
22
+ ["N", /^\p{N}$/u],
23
+ ["Nd", /^\p{Nd}$/u],
24
+ ["Nl", /^\p{Nl}$/u],
25
+ ["No", /^\p{No}$/u],
26
+ ["P", /^\p{P}$/u],
27
+ ["Pc", /^\p{Pc}$/u],
28
+ ["Pd", /^\p{Pd}$/u],
29
+ ["Pe", /^\p{Pe}$/u],
30
+ ["Pf", /^\p{Pf}$/u],
31
+ ["Pi", /^\p{Pi}$/u],
32
+ ["Po", /^\p{Po}$/u],
33
+ ["Ps", /^\p{Ps}$/u],
34
+ ["Z", /^\p{Z}$/u],
35
+ ["Zl", /^\p{Zl}$/u],
36
+ ["Zp", /^\p{Zp}$/u],
37
+ ["Zs", /^\p{Zs}$/u],
38
+ ["S", /^\p{S}$/u],
39
+ ["Sc", /^\p{Sc}$/u],
40
+ ["Sk", /^\p{Sk}$/u],
41
+ ["Sm", /^\p{Sm}$/u],
42
+ ["So", /^\p{So}$/u],
43
+ ["C", /^\p{C}$/u],
44
+ ["Cc", /^\p{Cc}$/u],
45
+ ["Cf", /^\p{Cf}$/u],
46
+ ["Cn", /^\p{Cn}$/u],
47
+ ["Co", /^\p{Co}$/u],
48
+ ]);
49
+ //# sourceMappingURL=_unicode-category.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_unicode-category.js","sourceRoot":"","sources":["../src/_unicode-category.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAgC,IAAI,GAAG,CAAC;IAC3E,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;IACnB,CAAC,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./ast.js";
2
+ export * from "./iregexp-syntax-error.js";
3
+ export * from "./iregexp.js";
2
4
  export * from "./lexer.js";
3
5
  export * from "./limits.js";
4
6
  export * from "./parser.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./ast.js";
2
+ export * from "./iregexp-syntax-error.js";
3
+ export * from "./iregexp.js";
2
4
  export * from "./lexer.js";
3
5
  export * from "./limits.js";
4
6
  export * from "./parser.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Span } from "@ac-kit/core";
2
+ /**
3
+ * Thrown by {@link compileIRegexp} when a pattern is not an RFC 9485 I-Regexp.
4
+ *
5
+ * A `SyntaxError`, so a caller treating any malformed pattern alike (a JSONPath
6
+ * `match()` answering false) can catch it without knowing this package.
7
+ */
8
+ export declare class IRegexpSyntaxError extends SyntaxError {
9
+ /** The code-unit range of the source the parser gave up at. */
10
+ readonly span: Span;
11
+ constructor(message: string, span: Span);
12
+ }
13
+ //# sourceMappingURL=iregexp-syntax-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iregexp-syntax-error.d.ts","sourceRoot":"","sources":["../src/iregexp-syntax-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,WAAW;IAClD,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAEpB,YAAY,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAItC;CACD"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Thrown by {@link compileIRegexp} when a pattern is not an RFC 9485 I-Regexp.
3
+ *
4
+ * A `SyntaxError`, so a caller treating any malformed pattern alike (a JSONPath
5
+ * `match()` answering false) can catch it without knowing this package.
6
+ */
7
+ export class IRegexpSyntaxError extends SyntaxError {
8
+ /** The code-unit range of the source the parser gave up at. */
9
+ span;
10
+ constructor(message, span) {
11
+ super(message);
12
+ this.name = "IRegexpSyntaxError";
13
+ this.span = span;
14
+ }
15
+ }
16
+ //# sourceMappingURL=iregexp-syntax-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iregexp-syntax-error.js","sourceRoot":"","sources":["../src/iregexp-syntax-error.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAClD,+DAA+D;IACtD,IAAI,CAAO;IAEpB,YAAY,OAAe,EAAE,IAAU;QACtC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD"}
@@ -0,0 +1,91 @@
1
+ import { type WorkBudget } from "@ac-kit/core";
2
+ import { type RegexLimits } from "./limits.js";
3
+ /** A compiled RFC 9485 I-Regexp, ready to test strings repeatedly. */
4
+ export interface IRegexp {
5
+ /** The pattern text it was compiled from. */
6
+ readonly source: string;
7
+ /**
8
+ * Whether the whole of `input` matches: RFC 9485 semantics, and JSONPath's
9
+ * `match()` (RFC 9535 §2.4.6). Unary and unbound, so `texts.filter(re.match)`
10
+ * works.
11
+ *
12
+ * O(program size × input length), by code point; O(program size) memory.
13
+ *
14
+ * @throws {RegexLimitExceededError} If the run outgrows
15
+ * {@link RegexLimits.maxSteps}.
16
+ */
17
+ readonly match: (input: string) => boolean;
18
+ /**
19
+ * Whether some substring of `input` matches: JSONPath's `search()` (RFC 9535
20
+ * §2.4.7). Unary and unbound, as {@link IRegexp.match}.
21
+ *
22
+ * @throws {RegexLimitExceededError} If the run outgrows
23
+ * {@link RegexLimits.maxSteps}.
24
+ */
25
+ readonly search: (input: string) => boolean;
26
+ /**
27
+ * {@link IRegexp.match}, charged to `budget` instead of a fresh allowance of
28
+ * {@link RegexLimits.maxSteps}.
29
+ *
30
+ * @throws Whatever `budget.spend` throws.
31
+ */
32
+ readonly matchWithin: (input: string, budget: WorkBudget) => boolean;
33
+ /**
34
+ * {@link IRegexp.search}, charged to `budget` instead of a fresh allowance of
35
+ * {@link RegexLimits.maxSteps}.
36
+ *
37
+ * @throws Whatever `budget.spend` throws.
38
+ */
39
+ readonly searchWithin: (input: string, budget: WorkBudget) => boolean;
40
+ }
41
+ /**
42
+ * Compiles an RFC 9485 I-Regexp onto this package's Pike VM.
43
+ *
44
+ * The pattern is checked against RFC 9485 §3 exactly: no `\d`/`\w`/`\s`, no
45
+ * lazy quantifiers, no `(?:`, no backreferences, no escapes beyond the RFC's
46
+ * (`\-` yes, `\/` or `\$` no), and `\p{…}`/`\P{…}` only with the general
47
+ * categories the RFC lists. Matching is by code point (an astral character is
48
+ * one `.`, class ranges compare code points), `.` excludes only `\n` and `\r`,
49
+ * and categories follow the JavaScript engine's Unicode version. Groups do not
50
+ * capture.
51
+ *
52
+ * Deviation, shared with the JSONPath compliance test suite: `^` and `$`
53
+ * outside a class are anchors (start and end of input), as in the ECMAScript
54
+ * mapping of RFC 9485 §5.3, rather than the literal characters of the XSD
55
+ * grammar. A literal caret or dollar is written `\^` or `[$]`.
56
+ *
57
+ * Both answers are compiled up front, so the program-size bound applies to
58
+ * each. Linear in the input and never backtracking, whatever the pattern.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const date = compileIRegexp("[0-9]{4}-[0-9]{2}-[0-9]{2}");
63
+ * date.match("2026-11-24"); // true
64
+ * date.search("due 2026-11-24."); // true
65
+ * compileIRegexp("a.b").match("a😀b"); // true: one code point
66
+ * ```;
67
+ *
68
+ * @param limits - Bounds on the program and on each run; see
69
+ * {@link RegexLimits}.
70
+ * @param budget - Charged for the compilation, before each piece of work: the
71
+ * source length before parsing, each class's normalisation by its item count,
72
+ * one unit per node lowered and per jump patched; a fresh allowance of
73
+ * {@link RegexLimits.maxSteps} when omitted.
74
+ * @throws {IRegexpSyntaxError} If `source` is not an I-Regexp.
75
+ * @throws {RegexLimitExceededError} If groups nest deeper than
76
+ * {@link RegexLimits.maxNestingDepth}, a program outgrows
77
+ * {@link RegexLimits.maxProgramSize}, or compiling outgrows its allowance.
78
+ */
79
+ export declare function compileIRegexp(source: string, limits?: RegexLimits, budget?: WorkBudget): IRegexp;
80
+ /**
81
+ * {@link compileIRegexp}, answering `null` where `source` is not an I-Regexp —
82
+ * the case JSONPath's `match()` and `search()` turn into false.
83
+ *
84
+ * @throws {RegexLimitExceededError} As {@link compileIRegexp} does: a pattern
85
+ * too large to compile is a fault to report, not a non-match.
86
+ * @throws Whatever `budget.spend` throws, unchanged — even an
87
+ * `IRegexpSyntaxError`: only errors raised by this call's parse become
88
+ * `null`.
89
+ */
90
+ export declare function tryCompileIRegexp(source: string, limits?: RegexLimits, budget?: WorkBudget): IRegexp | null;
91
+ //# sourceMappingURL=iregexp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iregexp.d.ts","sourceRoot":"","sources":["../src/iregexp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAkB,MAAM,cAAc,CAAC;AAQ9E,OAAO,EAAE,KAAK,WAAW,EAA+B,MAAM,aAAa,CAAC;AAK5E,sEAAsE;AACtE,MAAM,WAAW,OAAO;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAE3C;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAE5C;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IAErE;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;CACtE;AA6BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,UAAU,GACjB,OAAO,CAET;AA8BD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,UAAU,GACjB,OAAO,GAAG,IAAI,CAWhB"}
@@ -0,0 +1,111 @@
1
+ import { withWorkBudget } from "@ac-kit/core";
2
+ import { parseIRegexp_, shapeOfIRegexpNode_, } from "./_iregexp-parse.js";
3
+ import { regexLimits, stepsExceeded_ } from "./limits.js";
4
+ import { emitThompson, ProgramBuilder } from "./vm/_thompson.js";
5
+ import { testProgram } from "./vm/pike-vm.js";
6
+ function compileIRegexpProgram_(tree, anchored, maxProgramSize, budget) {
7
+ const builder = new ProgramBuilder(maxProgramSize);
8
+ if (anchored) {
9
+ emitThompson(builder, tree, shapeOfIRegexpNode_, budget);
10
+ builder.emit({ op: "assertEnd" });
11
+ builder.emit({ op: "match" });
12
+ }
13
+ else {
14
+ // split try, consume ; try: <body> match ; consume: anyByte ; jmp split
15
+ const scanSplit = builder.emit({ op: "split", first: -1, second: -1 });
16
+ emitThompson(builder, tree, shapeOfIRegexpNode_, budget);
17
+ builder.emit({ op: "match" });
18
+ const consume = builder.emit({ op: "anyByte" });
19
+ builder.emit({ op: "jmp", target: scanSplit });
20
+ builder.patchSplit(scanSplit, scanSplit + 1, consume);
21
+ }
22
+ return {
23
+ instructions: builder.toInstructions(),
24
+ groupCount: 0,
25
+ unit: "codePoint",
26
+ };
27
+ }
28
+ /**
29
+ * Compiles an RFC 9485 I-Regexp onto this package's Pike VM.
30
+ *
31
+ * The pattern is checked against RFC 9485 §3 exactly: no `\d`/`\w`/`\s`, no
32
+ * lazy quantifiers, no `(?:`, no backreferences, no escapes beyond the RFC's
33
+ * (`\-` yes, `\/` or `\$` no), and `\p{…}`/`\P{…}` only with the general
34
+ * categories the RFC lists. Matching is by code point (an astral character is
35
+ * one `.`, class ranges compare code points), `.` excludes only `\n` and `\r`,
36
+ * and categories follow the JavaScript engine's Unicode version. Groups do not
37
+ * capture.
38
+ *
39
+ * Deviation, shared with the JSONPath compliance test suite: `^` and `$`
40
+ * outside a class are anchors (start and end of input), as in the ECMAScript
41
+ * mapping of RFC 9485 §5.3, rather than the literal characters of the XSD
42
+ * grammar. A literal caret or dollar is written `\^` or `[$]`.
43
+ *
44
+ * Both answers are compiled up front, so the program-size bound applies to
45
+ * each. Linear in the input and never backtracking, whatever the pattern.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const date = compileIRegexp("[0-9]{4}-[0-9]{2}-[0-9]{2}");
50
+ * date.match("2026-11-24"); // true
51
+ * date.search("due 2026-11-24."); // true
52
+ * compileIRegexp("a.b").match("a😀b"); // true: one code point
53
+ * ```;
54
+ *
55
+ * @param limits - Bounds on the program and on each run; see
56
+ * {@link RegexLimits}.
57
+ * @param budget - Charged for the compilation, before each piece of work: the
58
+ * source length before parsing, each class's normalisation by its item count,
59
+ * one unit per node lowered and per jump patched; a fresh allowance of
60
+ * {@link RegexLimits.maxSteps} when omitted.
61
+ * @throws {IRegexpSyntaxError} If `source` is not an I-Regexp.
62
+ * @throws {RegexLimitExceededError} If groups nest deeper than
63
+ * {@link RegexLimits.maxNestingDepth}, a program outgrows
64
+ * {@link RegexLimits.maxProgramSize}, or compiling outgrows its allowance.
65
+ */
66
+ export function compileIRegexp(source, limits, budget) {
67
+ return compileIRegexp_(source, limits, budget);
68
+ }
69
+ function compileIRegexp_(source, limits, budget, onSyntaxError) {
70
+ const { maxProgramSize, maxSteps, maxNestingDepth } = regexLimits(limits);
71
+ const [whole, anywhere] = withWorkBudget(budget ?? maxSteps, (work) => {
72
+ work.spend(source.length + 1);
73
+ const tree = parseIRegexp_(source, maxNestingDepth, work, onSyntaxError);
74
+ return [
75
+ compileIRegexpProgram_(tree, true, maxProgramSize, work),
76
+ compileIRegexpProgram_(tree, false, maxProgramSize, work),
77
+ ];
78
+ }, stepsExceeded_);
79
+ return {
80
+ source,
81
+ match: (input) => testProgram(whole, input, maxSteps),
82
+ search: (input) => testProgram(anywhere, input, maxSteps),
83
+ matchWithin: (input, runBudget) => testProgram(whole, input, runBudget),
84
+ searchWithin: (input, runBudget) => testProgram(anywhere, input, runBudget),
85
+ };
86
+ }
87
+ /**
88
+ * {@link compileIRegexp}, answering `null` where `source` is not an I-Regexp —
89
+ * the case JSONPath's `match()` and `search()` turn into false.
90
+ *
91
+ * @throws {RegexLimitExceededError} As {@link compileIRegexp} does: a pattern
92
+ * too large to compile is a fault to report, not a non-match.
93
+ * @throws Whatever `budget.spend` throws, unchanged — even an
94
+ * `IRegexpSyntaxError`: only errors raised by this call's parse become
95
+ * `null`.
96
+ */
97
+ export function tryCompileIRegexp(source, limits, budget) {
98
+ let syntaxError;
99
+ try {
100
+ return compileIRegexp_(source, limits, budget, (error) => {
101
+ syntaxError = error;
102
+ });
103
+ }
104
+ catch (error) {
105
+ // A budget can rethrow an error from another parse.
106
+ if (syntaxError !== undefined && error === syntaxError)
107
+ return null;
108
+ throw error;
109
+ }
110
+ }
111
+ //# sourceMappingURL=iregexp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iregexp.js","sourceRoot":"","sources":["../src/iregexp.ts"],"names":[],"mappings":"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"}
package/dist/limits.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import type { WorkBudgetExceededError } from "@ac-kit/core";
1
2
  /**
2
- * Bounds on what a pattern may cost to compile and to run.
3
+ * Bounds on what a pattern may cost to parse, compile and run.
3
4
  *
4
5
  * The Pike VM gives an unconditional linear _time_ guarantee, but linear in a
5
6
  * program the pattern itself sizes: `a{1,200000}` expands to one instruction
@@ -16,28 +17,44 @@ export type RegexLimits = {
16
17
  */
17
18
  readonly maxProgramSize?: number;
18
19
  /**
19
- * Most thread activations one {@link execProgram} call may perform.
20
+ * Most work units one compilation, or one run, may spend when no shared
21
+ * `WorkBudget` (`@ac-kit/core`) is given.
20
22
  *
21
- * Bounds run-time work, which grows as program size × input length even
22
- * though neither factor alone is unbounded.
23
+ * A run spends one unit per thread activation plus its setup (one unit per
24
+ * instruction for each per-run table); a compilation spends one unit per
25
+ * syntax node it lowers. Bounds work that grows as program size × input
26
+ * length even though neither factor alone is unbounded. A positive integer or
27
+ * `Infinity`; exceeding it throws {@link RegexLimitExceededError} of kind
28
+ * `"steps"`.
23
29
  */
24
30
  readonly maxSteps?: number;
31
+ /**
32
+ * Most groups a pattern may nest inside one another.
33
+ *
34
+ * The parsers and compilers are iterative, so this does not protect them; it
35
+ * bounds the depth of the syntax tree {@link parseRegex} hands out, so a
36
+ * caller walking it recursively cannot be driven into a stack overflow.
37
+ */
38
+ readonly maxNestingDepth?: number;
25
39
  };
26
40
  /**
27
41
  * Defaults, chosen so no hand-written pattern over a realistic input reaches
28
42
  * them: 64 Ki instructions is about three orders of magnitude above any regex a
29
- * person writes, and 16 Mi steps covers a 100-instruction program over a 100 Ki
30
- * character input.
43
+ * person writes, 16 Mi steps covers a 100-instruction program over a 100 Ki
44
+ * character input, and 256 nested groups is two orders above any regex a person
45
+ * writes.
31
46
  */
32
47
  export declare const DEFAULT_REGEX_LIMITS: Required<RegexLimits>;
33
48
  /** Which bound a {@link RegexLimitExceededError} reports. */
34
- export type RegexLimitKind = "programSize" | "steps";
49
+ export type RegexLimitKind = "programSize" | "steps" | "nestingDepth";
35
50
  /** Thrown when a pattern exceeds one of the {@link RegexLimits}. */
36
51
  export declare class RegexLimitExceededError extends Error {
37
52
  readonly kind: RegexLimitKind;
38
53
  readonly limit: number;
39
- constructor(kind: RegexLimitKind, limit: number);
54
+ constructor(kind: RegexLimitKind, limit: number, options?: ErrorOptions);
40
55
  }
56
+ /** Translates a private step budget's exhaustion into the package's own error. */
57
+ export declare function stepsExceeded_(cause: WorkBudgetExceededError): RegexLimitExceededError;
41
58
  /** Fills in the unset bounds from {@link DEFAULT_REGEX_LIMITS}. */
42
59
  export declare function regexLimits(limits?: RegexLimits): Required<RegexLimits>;
43
60
  //# sourceMappingURL=limits.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAGtD,CAAC;AAEF,6DAA6D;AAC7D,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,OAAO,CAAC;AAErD,oEAAoE;AACpE,qBAAa,uBAAwB,SAAQ,KAAK;IAEhD,QAAQ,CAAC,IAAI,EAAE,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM;IAFvB,YACU,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,MAAM,EAQtB;CACD;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,CAMvE"}
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAItD,CAAC;AAEF,6DAA6D;AAC7D,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,OAAO,GAAG,cAAc,CAAC;AAQtE,oEAAoE;AACpE,qBAAa,uBAAwB,SAAQ,KAAK;IAEhD,QAAQ,CAAC,IAAI,EAAE,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM;IAFvB,YACU,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,YAAY,EAItB;CACD;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAC7B,KAAK,EAAE,uBAAuB,GAC5B,uBAAuB,CAEzB;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,CAQvE"}
package/dist/limits.js CHANGED
@@ -1,31 +1,41 @@
1
1
  /**
2
2
  * Defaults, chosen so no hand-written pattern over a realistic input reaches
3
3
  * them: 64 Ki instructions is about three orders of magnitude above any regex a
4
- * person writes, and 16 Mi steps covers a 100-instruction program over a 100 Ki
5
- * character input.
4
+ * person writes, 16 Mi steps covers a 100-instruction program over a 100 Ki
5
+ * character input, and 256 nested groups is two orders above any regex a person
6
+ * writes.
6
7
  */
7
8
  export const DEFAULT_REGEX_LIMITS = {
8
9
  maxProgramSize: 65536,
9
10
  maxSteps: 16777216,
11
+ maxNestingDepth: 256,
12
+ };
13
+ const LIMIT_MESSAGES_ = {
14
+ programSize: "Compiled regex program exceeds {limit} instructions",
15
+ steps: "Regex work exceeded {limit} steps",
16
+ nestingDepth: "Regex pattern nests groups deeper than {limit}",
10
17
  };
11
18
  /** Thrown when a pattern exceeds one of the {@link RegexLimits}. */
12
19
  export class RegexLimitExceededError extends Error {
13
20
  kind;
14
21
  limit;
15
- constructor(kind, limit) {
16
- super(kind === "programSize"
17
- ? `Compiled regex program exceeds ${limit} instructions`
18
- : `Regex execution exceeded ${limit} steps`);
22
+ constructor(kind, limit, options) {
23
+ super(LIMIT_MESSAGES_[kind].replace("{limit}", String(limit)), options);
19
24
  this.kind = kind;
20
25
  this.limit = limit;
21
26
  this.name = "RegexLimitExceededError";
22
27
  }
23
28
  }
29
+ /** Translates a private step budget's exhaustion into the package's own error. */
30
+ export function stepsExceeded_(cause) {
31
+ return new RegexLimitExceededError("steps", cause.limit, { cause });
32
+ }
24
33
  /** Fills in the unset bounds from {@link DEFAULT_REGEX_LIMITS}. */
25
34
  export function regexLimits(limits) {
26
35
  return {
27
36
  maxProgramSize: limits?.maxProgramSize ?? DEFAULT_REGEX_LIMITS.maxProgramSize,
28
37
  maxSteps: limits?.maxSteps ?? DEFAULT_REGEX_LIMITS.maxSteps,
38
+ maxNestingDepth: limits?.maxNestingDepth ?? DEFAULT_REGEX_LIMITS.maxNestingDepth,
29
39
  };
30
40
  }
31
41
  //# sourceMappingURL=limits.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AA2BA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B;IAC1D,cAAc,EAAE,KAAM;IACtB,QAAQ,EAAE,QAAU;CACpB,CAAC;AAKF,oEAAoE;AACpE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAEvC,IAAI;IACJ,KAAK;IAFf,YACU,IAAoB,EACpB,KAAa;QAEtB,KAAK,CACJ,IAAI,KAAK,aAAa;YACrB,CAAC,CAAC,kCAAkC,KAAK,eAAe;YACxD,CAAC,CAAC,4BAA4B,KAAK,QAAQ,CAC5C,CAAC;oBAPO,IAAI;qBACJ,KAAK;QAOd,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAED,mEAAmE;AACnE,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC/C,OAAO;QACN,cAAc,EACb,MAAM,EAAE,cAAc,IAAI,oBAAoB,CAAC,cAAc;QAC9D,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,oBAAoB,CAAC,QAAQ;KAC3D,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AA2CA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B;IAC1D,cAAc,EAAE,KAAM;IACtB,QAAQ,EAAE,QAAU;IACpB,eAAe,EAAE,GAAG;CACpB,CAAC;AAKF,MAAM,eAAe,GAA6C;IACjE,WAAW,EAAE,qDAAqD;IAClE,KAAK,EAAE,mCAAmC;IAC1C,YAAY,EAAE,gDAAgD;CAC9D,CAAC;AAEF,oEAAoE;AACpE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAEvC,IAAI;IACJ,KAAK;IAFf,YACU,IAAoB,EACpB,KAAa,EACtB,OAAsB;QAEtB,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;oBAJ/D,IAAI;qBACJ,KAAK;QAId,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAED,kFAAkF;AAClF,MAAM,UAAU,cAAc,CAC7B,KAA8B;IAE9B,OAAO,IAAI,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AACrE,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC/C,OAAO;QACN,cAAc,EACb,MAAM,EAAE,cAAc,IAAI,oBAAoB,CAAC,cAAc;QAC9D,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,oBAAoB,CAAC,QAAQ;QAC3D,eAAe,EACd,MAAM,EAAE,eAAe,IAAI,oBAAoB,CAAC,eAAe;KAChE,CAAC;AACH,CAAC"}
package/dist/parser.d.ts CHANGED
@@ -1,9 +1,22 @@
1
- import type { Span } from "@ac-kit/core";
1
+ import { type Span } from "@ac-kit/core";
2
2
  import type { RegexPattern } from "./ast.js";
3
+ import { type RegexLimits } from "./limits.js";
3
4
  export declare class RegexParseError extends Error {
4
5
  readonly span: Span;
5
6
  constructor(message: string, span: Span);
6
7
  }
7
- /** Parses a regex pattern into a {@link RegexPattern} AST. */
8
- export declare function parseRegex(source: string): RegexPattern;
8
+ /**
9
+ * Parses a regex pattern into a {@link RegexPattern} AST.
10
+ *
11
+ * Iterative: open groups live on an explicit stack, so nesting depth never
12
+ * grows the JavaScript stack. O(source length) time and memory.
13
+ *
14
+ * @param limits - Only {@link RegexLimits.maxNestingDepth} is read here.
15
+ * @throws {RegexLexerError} If `source` holds an unsupported construct.
16
+ * @throws {RegexParseError} If the tokens do not form a pattern.
17
+ * @throws {RegexLimitExceededError} If groups nest deeper than
18
+ * {@link RegexLimits.maxNestingDepth}, so the tree handed out is never deeper
19
+ * than a recursive walk can follow.
20
+ */
21
+ export declare function parseRegex(source: string, limits?: RegexLimits): RegexPattern;
9
22
  //# sourceMappingURL=parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAGX,YAAY,EAEZ,MAAM,UAAU,CAAC;AAIlB,qBAAa,eAAgB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,YAAY,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAItC;CACD;AAQD,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAmPvD"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,IAAI,EACT,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAGX,YAAY,EAEZ,MAAM,UAAU,CAAC;AAElB,OAAO,EAEN,KAAK,WAAW,EAEhB,MAAM,aAAa,CAAC;AAGrB,qBAAa,eAAgB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,YAAY,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAItC;CACD;AAkBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,YAAY,CA8Q7E"}