@descent-vtt/spec-graph 0.5.0 → 0.7.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/dist/regex.js CHANGED
@@ -35,10 +35,12 @@
35
35
  * whole trade: a predicate that finishes, against a short list of constructs
36
36
  * that a documentation selector never needed.
37
37
  *
38
- * Matching is case-insensitive and unanchored because that is what `~=` has
39
- * always been - `new RegExp(source, 'i')` and `.test()`. There are no capture
40
- * groups at all: nothing asks where the match was, only whether there was one,
41
- * which is why this is a plain NFA simulation rather than a Pike VM.
38
+ * Matching is unanchored and, by default, case-insensitive, because that is
39
+ * what `~=` has always been - `new RegExp(source, 'i')` and `.test()`. Globs
40
+ * compile to this as well, and a path on a case-sensitive filesystem needs the
41
+ * case respected, which is the one option. There are no capture groups at all:
42
+ * nothing asks where the match was, only whether there was one, which is why
43
+ * this is a plain NFA simulation rather than a Pike VM.
42
44
  *
43
45
  * See ADR-0017.
44
46
  */
@@ -100,6 +102,10 @@ const SPACE = [
100
102
  * the reason U+017F (long s) does not match `s`.
101
103
  */
102
104
  function canonical(code) {
105
+ // Every subject a glob sees is mostly ASCII, where the answer needs no string.
106
+ // The general path below gives the same answer here, only slower.
107
+ if (code < 128)
108
+ return code >= 97 && code <= 122 ? code - 32 : code;
103
109
  const upper = String.fromCharCode(code).toUpperCase();
104
110
  if (upper.length !== 1)
105
111
  return code;
@@ -122,7 +128,8 @@ function canonical(code) {
122
128
  function accepts(set, code) {
123
129
  const folded = canonical(code);
124
130
  let hit = false;
125
- for (const [low, high] of set.ranges) {
131
+ for (let i = 0; i < set.ranges.length; i += 1) {
132
+ const [low, high] = set.ranges[i];
126
133
  if (low === high ? low === code || canonical(low) === folded : inRange(low, high, code)) {
127
134
  hit = true;
128
135
  break;
@@ -143,6 +150,12 @@ function accepts(set, code) {
143
150
  function inRange(low, high, code) {
144
151
  if (code >= low && code <= high)
145
152
  return true;
153
+ // An ASCII character's only other case form is its ASCII letter twin, and the
154
+ // two always fold together - so the loop below would ask exactly this.
155
+ if (code < 128) {
156
+ const twin = code >= 65 && code <= 90 ? code + 32 : code >= 97 && code <= 122 ? code - 32 : -1;
157
+ return twin >= low && twin <= high;
158
+ }
146
159
  const folded = canonical(code);
147
160
  const char = String.fromCharCode(code);
148
161
  for (const variant of [char.toLowerCase(), char.toUpperCase()]) {
@@ -154,9 +167,19 @@ function inRange(low, high, code) {
154
167
  }
155
168
  return false;
156
169
  }
170
+ /**
171
+ * Whether a set accepts a code unit as written.
172
+ *
173
+ * What `RegExp` does without the `i` flag, and so none of the folding above
174
+ * applies - which also means none of its one divergence does.
175
+ */
176
+ function acceptsExactly(set, code) {
177
+ return within(set.ranges, code) !== set.negated;
178
+ }
157
179
  function within(ranges, code) {
158
- for (const [low, high] of ranges) {
159
- if (code >= low && code <= high)
180
+ for (let i = 0; i < ranges.length; i += 1) {
181
+ const range = ranges[i];
182
+ if (code >= range[0] && code <= range[1])
160
183
  return true;
161
184
  }
162
185
  return false;
@@ -594,20 +617,19 @@ class Compiler {
594
617
  * Throws {@link PatternError} on anything it cannot run in linear time, which
595
618
  * is the point: the alternative to a message here is a build that stops.
596
619
  */
597
- export function compilePattern(source) {
620
+ export function compilePattern(source, options = {}) {
598
621
  const tree = new PatternParser(source).parse();
599
622
  const compiler = new Compiler();
600
623
  compiler.compile(tree);
601
624
  compiler.emitMatch();
602
- const code = compiler.code;
603
625
  // A pattern that begins by asserting the start of the subject cannot match
604
626
  // anywhere else, so the simulation stops seeding new threads at every
605
627
  // position. Nothing depends on this being noticed - it is the difference
606
628
  // between one pass and two over a long body.
607
- const anchored = startsAnchored(tree);
629
+ const machine = new Machine(compiler.code, startsAnchored(tree), options.ignoreCase !== false);
608
630
  return {
609
- size: code.length,
610
- test: (subject) => run(code, subject, anchored),
631
+ size: compiler.code.length,
632
+ test: (subject) => machine.test(subject),
611
633
  };
612
634
  }
613
635
  /** True when every path through the pattern opens by asserting the start. */
@@ -627,70 +649,162 @@ function startsAnchored(node) {
627
649
  return false;
628
650
  }
629
651
  }
630
- function run(code, subject, anchored) {
631
- const length = subject.length;
632
- // The position each state was last reached at. One visit per state per
633
- // position is exactly what turns the exponent into a product.
634
- const visited = new Int32Array(code.length).fill(-1);
635
- let live = [];
636
- for (let position = 0; position <= length; position += 1) {
637
- if (position === 0 || !anchored) {
638
- if (seedFrom(code, visited, live, 0, subject, position))
639
- return true;
640
- }
641
- else if (live.length === 0) {
642
- // An anchored pattern gets one chance, and every thread from it has died.
643
- return false;
644
- }
645
- if (position === length)
646
- return false;
647
- const char = subject.charCodeAt(position);
648
- const next = [];
649
- for (const pc of live) {
650
- const instruction = code[pc];
651
- if (instruction.op !== 'char' || !accepts(instruction.set, char))
652
- continue;
653
- if (seedFrom(code, visited, next, pc + 1, subject, position + 1))
654
- return true;
655
- }
656
- live = next;
657
- }
658
- return false;
659
- }
652
+ const OP_CHAR = 0;
653
+ const OP_SPLIT = 1;
654
+ const OP_JUMP = 2;
655
+ const OP_ASSERT = 3;
656
+ const OP_MATCH = 4;
657
+ /** Fills the slots of states that are not characters, where nothing reads it. */
658
+ const NOTHING = { negated: false, ranges: [] };
660
659
  /**
661
- * Follows every zero-width transition out of one state.
660
+ * The simulation, over the program flattened into typed arrays.
662
661
  *
663
- * Returns true the moment a thread reaches the end of the pattern: the only
664
- * question is whether a match exists, so there is no leftmost-longest to settle
665
- * and no captures to keep, and the first thread to arrive is the answer.
662
+ * The compiler's instructions are objects of five shapes, and one loop reading
663
+ * `op` off all five is a megamorphic property read on every step. Simulated that
664
+ * way, with a fresh visited table per subject, a glob cost about 3.5
665
+ * microseconds a path and a path that failed on its first character still paid
666
+ * half a microsecond for the allocation. Flat arrays and buffers kept between
667
+ * subjects bring those to 0.6 and 0.04 - `RegExp` takes 0.06 - which matters
668
+ * because a walk tests every path it visits against every pattern.
666
669
  */
667
- function seedFrom(code, visited, list, start, subject, position) {
668
- const stack = [start];
669
- while (stack.length > 0) {
670
- const pc = stack.pop();
671
- if (visited[pc] === position)
672
- continue;
673
- visited[pc] = position;
674
- const instruction = code[pc];
675
- switch (instruction.op) {
676
- case 'match':
677
- return true;
678
- case 'jump':
679
- stack.push(instruction.to);
680
- break;
681
- case 'split':
682
- stack.push(instruction.y, instruction.x);
683
- break;
684
- case 'assert':
685
- if (holds(instruction.assertion, subject, position))
686
- stack.push(pc + 1);
687
- break;
688
- case 'char':
689
- list.push(pc);
690
- break;
670
+ class Machine {
671
+ ops;
672
+ /** A split's first branch, or a jump's target. */
673
+ first;
674
+ /** A split's second branch. */
675
+ second;
676
+ sets;
677
+ assertions;
678
+ anchored;
679
+ ignoreCase;
680
+ /**
681
+ * The position each state was last reached at. One visit per state per
682
+ * position is exactly what turns the exponent into a product.
683
+ */
684
+ visited;
685
+ /** Each visit pushes at most two states, so this cannot overflow. */
686
+ stack;
687
+ live;
688
+ next;
689
+ constructor(code, anchored, ignoreCase) {
690
+ const size = code.length;
691
+ this.ops = new Uint8Array(size);
692
+ this.first = new Int32Array(size);
693
+ this.second = new Int32Array(size);
694
+ this.sets = new Array(size).fill(NOTHING);
695
+ this.assertions = new Array(size).fill('start');
696
+ this.anchored = anchored;
697
+ this.ignoreCase = ignoreCase;
698
+ this.visited = new Int32Array(size).fill(-1);
699
+ this.stack = new Int32Array(2 * size + 1);
700
+ this.live = new Int32Array(size);
701
+ this.next = new Int32Array(size);
702
+ code.forEach((instruction, pc) => {
703
+ switch (instruction.op) {
704
+ case 'char':
705
+ this.ops[pc] = OP_CHAR;
706
+ this.sets[pc] = instruction.set;
707
+ break;
708
+ case 'split':
709
+ this.ops[pc] = OP_SPLIT;
710
+ this.first[pc] = instruction.x;
711
+ this.second[pc] = instruction.y;
712
+ break;
713
+ case 'jump':
714
+ this.ops[pc] = OP_JUMP;
715
+ this.first[pc] = instruction.to;
716
+ break;
717
+ case 'assert':
718
+ this.ops[pc] = OP_ASSERT;
719
+ this.assertions[pc] = instruction.assertion;
720
+ break;
721
+ case 'match':
722
+ this.ops[pc] = OP_MATCH;
723
+ break;
724
+ }
725
+ });
726
+ }
727
+ test(subject) {
728
+ const length = subject.length;
729
+ this.visited.fill(-1);
730
+ let live = this.live;
731
+ let next = this.next;
732
+ let alive = 0;
733
+ for (let position = 0; position <= length; position += 1) {
734
+ if (position === 0 || !this.anchored) {
735
+ alive = this.seed(live, alive, 0, subject, position);
736
+ if (alive < 0)
737
+ return true;
738
+ }
739
+ else if (alive === 0) {
740
+ // An anchored pattern gets one chance, and every thread from it has died.
741
+ return false;
742
+ }
743
+ if (position === length)
744
+ return false;
745
+ const char = subject.charCodeAt(position);
746
+ let arriving = 0;
747
+ for (let i = 0; i < alive; i += 1) {
748
+ const pc = live[i];
749
+ const set = this.sets[pc];
750
+ if (!(this.ignoreCase ? accepts(set, char) : acceptsExactly(set, char)))
751
+ continue;
752
+ arriving = this.seed(next, arriving, pc + 1, subject, position + 1);
753
+ if (arriving < 0)
754
+ return true;
755
+ }
756
+ const spent = live;
757
+ live = next;
758
+ next = spent;
759
+ alive = arriving;
691
760
  }
761
+ return false;
762
+ }
763
+ /**
764
+ * Follows every zero-width transition out of one state, appending the
765
+ * character states it reaches to `list`.
766
+ *
767
+ * Returns the new length of the list, or -1 the moment a thread reaches the
768
+ * end of the pattern: the only question is whether a match exists, so there
769
+ * is no leftmost-longest to settle and no captures to keep, and the first
770
+ * thread to arrive is the answer.
771
+ *
772
+ * A stray thread at state 0 changes no answer: an unanchored pattern seeds it
773
+ * at every position anyway, and an anchored one opens by asserting the start.
774
+ * That makes two mutants here equivalent, with no test to write - the loop
775
+ * running once past an empty stack, and a jump read as a split, both of which
776
+ * add exactly that thread.
777
+ */
778
+ seed(list, length, start, subject, position) {
779
+ const { ops, first, second, visited, stack } = this;
780
+ let count = length;
781
+ let top = 0;
782
+ stack[top++] = start;
783
+ while (top > 0) {
784
+ const pc = stack[--top];
785
+ if (visited[pc] === position)
786
+ continue;
787
+ visited[pc] = position;
788
+ switch (ops[pc]) {
789
+ case OP_MATCH:
790
+ return -1;
791
+ case OP_JUMP:
792
+ stack[top++] = first[pc];
793
+ break;
794
+ case OP_SPLIT:
795
+ stack[top++] = second[pc];
796
+ stack[top++] = first[pc];
797
+ break;
798
+ case OP_ASSERT:
799
+ if (holds(this.assertions[pc], subject, position))
800
+ stack[top++] = pc + 1;
801
+ break;
802
+ default:
803
+ list[count++] = pc;
804
+ }
805
+ }
806
+ return count;
692
807
  }
693
- return false;
694
808
  }
695
809
  function holds(assertion, subject, position) {
696
810
  switch (assertion) {
package/dist/regex.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"regex.js","sourceRoot":"","sources":["../src/regex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAEhF,2EAA2E;AAC3E,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,sCAAsC;IAC7B,MAAM,CAAS;IAExB,YAAY,OAAe,EAAE,MAAc;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,GAAG,IAAI,CAAC;AAsBzB,mFAAmF;AACnF,MAAM,GAAG,GAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;AAC/F,MAAM,KAAK,GAAqB,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC/C,MAAM,IAAI,GAAqB;IAC7B,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,IAAI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AAK,CAAC,KAAK,CAAC,SAAS,KAAK,eAAe,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * A regular-expression matcher that cannot backtrack.\n *\n * `~=` is the one predicate in the selector language that used to hand a\n * user-supplied string to `RegExp` and wait. That is tolerable at a prompt,\n * where a human can press Ctrl-C. It is not tolerable in `.spec-graph.json`,\n * where the same string runs unattended in CI against every node in the corpus.\n *\n * The cost is neither theoretical nor exotic. `^([A-Za-z0-9_]+[ ]?)+$` is what\n * somebody writes to say \"the title is words separated by single spaces\", and\n * against a title that does not match, V8 tries one branch per way of cutting\n * each word into pieces:\n *\n * ```text\n * RegExp here\n * the quick brown fox jumps over the lazy dog! 0.9s 11us\n * the quick brown fox jumps over the lazy dog and! 5.4s 12us\n * the quick brown fox jumps over the lazy dog and keeps! 103s 13us\n * ```\n *\n * Each word of k letters can be cut into pieces 2^(k-1) ways, and the engine\n * tries the product of those, which is why adding one five-letter word costs\n * another factor of sixteen. A sixty-character title does not finish this year.\n *\n * So a pattern here is compiled to a **non-deterministic finite automaton** and\n * simulated over the subject one character at a time (Thompson, 1968), keeping\n * a set of live states instead of a stack of choices. Each state is visited at\n * most once per position, which makes the work exactly O(pattern x subject):\n * the right-hand column above, growing with the subject and not with the\n * pattern's ambiguity.\n *\n * What it costs is a dialect. Backreferences and lookaround are not regular and\n * have no place in a linear automaton, so they are **rejected while compiling**,\n * with a message and an offset, rather than accepted and then slow. That is the\n * whole trade: a predicate that finishes, against a short list of constructs\n * that a documentation selector never needed.\n *\n * Matching is case-insensitive and unanchored because that is what `~=` has\n * always been - `new RegExp(source, 'i')` and `.test()`. There are no capture\n * groups at all: nothing asks where the match was, only whether there was one,\n * which is why this is a plain NFA simulation rather than a Pike VM.\n *\n * See ADR-0017.\n */\n\n/* -------------------------------------------------------------------------- */\n/* Errors */\n/* -------------------------------------------------------------------------- */\n\n/** A pattern that will not compile, and where in it the problem starts. */\nexport class PatternError extends Error {\n /** Offset into the pattern source. */\n readonly offset: number;\n\n constructor(message: string, offset: number) {\n super(message);\n this.name = 'PatternError';\n this.offset = offset;\n }\n}\n\n/**\n * Ceiling on the compiled program.\n *\n * Counted repetition is compiled by copying - `(ab){20}` is twenty copies -\n * which is part of what keeps the simulation flat, and also what makes\n * `(a{99}){99}` into ten thousand states. The bound has to live somewhere, and\n * a number checked while compiling is the only place it can be enforced without\n * measuring anything at match time.\n *\n * Far above any real selector: the widest pattern in this repository's own\n * tests compiles to seventeen states.\n */\nconst MAX_PROGRAM = 4096;\n\n/* -------------------------------------------------------------------------- */\n/* Character sets */\n/* -------------------------------------------------------------------------- */\n\n/** An inclusive range of UTF-16 code units. */\ntype Range = readonly [number, number];\n\n/**\n * A set of code units, as inclusive ranges.\n *\n * Code units rather than code points, because that is what a `RegExp` without\n * the `u` flag matches: `.` consumes one half of a surrogate pair, and so does\n * this. Agreeing with the engine this replaced matters more than being right\n * about astral planes, which no selector in any corpus has asked about.\n */\ninterface CharSet {\n readonly negated: boolean;\n readonly ranges: readonly Range[];\n}\n\n/** `.` - anything but a line terminator, which is the default `RegExp` reading. */\nconst DOT: CharSet = { negated: true, ranges: [[0x0a, 0x0a], [0x0d, 0x0d], [0x2028, 0x2029]] };\nconst DIGIT: readonly Range[] = [[0x30, 0x39]];\nconst WORD: readonly Range[] = [\n [0x30, 0x39],\n [0x41, 0x5a],\n [0x5f, 0x5f],\n [0x61, 0x7a],\n];\n/** `\\s`, taken from the specification rather than guessed at. */\nconst SPACE: readonly Range[] = [\n [0x09, 0x0d],\n [0x20, 0x20],\n [0xa0, 0xa0],\n [0x1680, 0x1680],\n [0x2000, 0x200a],\n [0x2028, 0x2029],\n [0x202f, 0x202f],\n [0x205f, 0x205f],\n [0x3000, 0x3000],\n [0xfeff, 0xfeff],\n];\n\n/**\n * Folds a code unit the way a case-insensitive `RegExp` does.\n *\n * This is `Canonicalize` from the language specification, non-Unicode mode:\n * upper-case the character, keep it unchanged if that produced anything other\n * than one code unit, and keep it unchanged if upper-casing dragged a\n * non-ASCII character into ASCII. The last clause is the one nobody expects and\n * the reason U+017F (long s) does not match `s`.\n */\nfunction canonical(code: number): number {\n const upper = String.fromCharCode(code).toUpperCase();\n if (upper.length !== 1) return code;\n const folded = upper.charCodeAt(0);\n if (code >= 128 && folded < 128) return code;\n return folded;\n}\n\n/**\n * Whether a set accepts a code unit, case-insensitively.\n *\n * The specification canonicalises both sides: a character matches a set when\n * *some* member of the set folds to the same thing it does. A single-character\n * member can be asked that exactly. A range cannot without a fold table for\n * every code unit, so a range is asked the question backwards - does the\n * character, or either of its own case forms, fall inside it - which is exact\n * for every character whose fold is its own case change, and therefore for\n * every range anyone has written.\n */\nfunction accepts(set: CharSet, code: number): boolean {\n const folded = canonical(code);\n let hit = false;\n for (const [low, high] of set.ranges) {\n if (low === high ? low === code || canonical(low) === folded : inRange(low, high, code)) {\n hit = true;\n break;\n }\n }\n return set.negated ? !hit : hit;\n}\n\n/**\n * Whether some member of a range folds to the same thing a code unit does.\n *\n * Asked backwards, by trying the character's own case forms against the raw\n * range - and then checking that the form found there really does fold to the\n * same place, which is the part that is easy to leave out. U+017F upper-cases\n * to `S`, so without that check it matches `[A-Z]`, and it must not: the fold\n * keeps it outside ASCII, which is the same clause `isWordChar` gets wrong if\n * nobody is watching. The differential corpus caught both.\n */\nfunction inRange(low: number, high: number, code: number): boolean {\n if (code >= low && code <= high) return true;\n const folded = canonical(code);\n const char = String.fromCharCode(code);\n for (const variant of [char.toLowerCase(), char.toUpperCase()]) {\n if (variant.length !== 1) continue;\n const candidate = variant.charCodeAt(0);\n if (candidate >= low && candidate <= high && canonical(candidate) === folded) return true;\n }\n return false;\n}\n\nfunction within(ranges: readonly Range[], code: number): boolean {\n for (const [low, high] of ranges) {\n if (code >= low && code <= high) return true;\n }\n return false;\n}\n\n/**\n * Word characters for `\\b`, which is exactly `\\w` here.\n *\n * The specification does widen this set under case-insensitivity - to every\n * character that folds into it, which is U+017F (long s) and U+212A (the\n * Kelvin sign) - but only in Unicode mode, where `Canonicalize` has no clause\n * keeping a non-ASCII character out of ASCII. This is the non-Unicode dialect,\n * so both stay outside and the table for `\\w` answers for `\\b` as well.\n *\n * Written down because the first version of this function widened the set, and\n * the differential test against `RegExp` is what said otherwise. Reading the\n * clause was not enough; running it was. See ADR-0017.\n */\nfunction isWordChar(code: number): boolean {\n return within(WORD, code);\n}\n\n/* -------------------------------------------------------------------------- */\n/* Syntax tree */\n/* -------------------------------------------------------------------------- */\n\ntype Assertion = 'start' | 'end' | 'word-boundary' | 'not-word-boundary';\n\ntype Node =\n | { readonly kind: 'empty' }\n | { readonly kind: 'char'; readonly set: CharSet }\n | { readonly kind: 'assert'; readonly assertion: Assertion }\n | { readonly kind: 'concat'; readonly parts: readonly Node[] }\n | { readonly kind: 'alternate'; readonly options: readonly Node[] }\n | { readonly kind: 'repeat'; readonly node: Node; readonly min: number; readonly max: number };\n\n/* -------------------------------------------------------------------------- */\n/* Parsing */\n/* -------------------------------------------------------------------------- */\n\nclass PatternParser {\n private readonly source: string;\n private position = 0;\n\n constructor(source: string) {\n this.source = source;\n }\n\n parse(): Node {\n const node = this.parseAlternation();\n // Every character is an atom except the two that close something, and\n // `parseSequence` stops on both, so anything left over is an unopened `)`.\n if (this.position < this.source.length) throw new PatternError('unmatched \")\"', this.position);\n return node;\n }\n\n private parseAlternation(): Node {\n const options: Node[] = [this.parseSequence()];\n while (this.peek() === '|') {\n this.position += 1;\n options.push(this.parseSequence());\n }\n return options.length === 1 ? (options[0] as Node) : { kind: 'alternate', options };\n }\n\n private parseSequence(): Node {\n const parts: Node[] = [];\n for (;;) {\n const char = this.peek();\n if (char === undefined || char === '|' || char === ')') break;\n parts.push(this.parseQuantified());\n }\n if (parts.length === 0) return { kind: 'empty' };\n return parts.length === 1 ? (parts[0] as Node) : { kind: 'concat', parts };\n }\n\n private parseQuantified(): Node {\n const start = this.position;\n // A group makes its contents quantifiable: `RegExp` rejects `\\b*` and\n // accepts `(\\b)*`, which is the same nothing said twice, and this parser\n // treats a group as transparent - so whether one was written is the only\n // thing left that distinguishes the two.\n const grouped = this.peek() === '(';\n const atom = this.parseAtom();\n const bounds = this.parseQuantifier();\n if (bounds === null) return atom;\n if (atom.kind === 'assert' && !grouped) {\n throw new PatternError('nothing to repeat: a quantifier cannot follow an anchor', start);\n }\n return { kind: 'repeat', node: atom, min: bounds.min, max: bounds.max };\n }\n\n /** `*`, `+`, `?`, `{n}`, `{n,}`, `{n,m}`, and a trailing `?` that is ignored. */\n private parseQuantifier(): { min: number; max: number } | null {\n const char = this.peek();\n let bounds: { min: number; max: number } | null = null;\n\n if (char === '*') bounds = { min: 0, max: Infinity };\n else if (char === '+') bounds = { min: 1, max: Infinity };\n else if (char === '?') bounds = { min: 0, max: 1 };\n\n if (bounds !== null) this.position += 1;\n else if (char === '{') bounds = this.parseBraces();\n if (bounds === null) return null;\n\n // Laziness decides *which* match is found, and nothing here asks: the\n // question is whether one exists, and a lazy quantifier accepts the same\n // language as a greedy one.\n if (this.peek() === '?') this.position += 1;\n return bounds;\n }\n\n /**\n * Reads `{n,m}`, or nothing.\n *\n * A `{` that does not open a counted repetition is a literal brace, which is\n * what `RegExp` does with `a{` and what any pattern written against a\n * document full of `{0}` placeholders depends on.\n */\n private parseBraces(): { min: number; max: number } | null {\n const match = /^\\{(\\d+)(?:(,)(\\d*))?\\}/.exec(this.source.slice(this.position));\n if (!match) return null;\n const min = Number(match[1]);\n const max = match[2] === undefined ? min : match[3] === '' ? Infinity : Number(match[3]);\n if (min > max) throw new PatternError('numbers out of order in a counted repetition', this.position);\n this.position += (match[0] as string).length;\n return { min, max };\n }\n\n private parseAtom(): Node {\n const start = this.position;\n const char = this.peek();\n\n switch (char) {\n case undefined:\n throw new PatternError('pattern ends where an expression was expected', start);\n case '(':\n return this.parseGroup();\n case '[':\n return { kind: 'char', set: this.parseClass() };\n case '.':\n this.position += 1;\n return { kind: 'char', set: DOT };\n case '^':\n this.position += 1;\n return { kind: 'assert', assertion: 'start' };\n case '$':\n this.position += 1;\n return { kind: 'assert', assertion: 'end' };\n case '*':\n case '+':\n throw new PatternError(`nothing to repeat before \"${char}\"`, start);\n case '\\\\':\n return this.parseEscape();\n default:\n this.position += 1;\n return { kind: 'char', set: literal(char.charCodeAt(0)) };\n }\n }\n\n /**\n * A group, which is never a capture.\n *\n * `(a)` and `(?:a)` compile to the same automaton because nothing downstream\n * can ask what `(a)` caught. A named group is accepted and its name dropped,\n * so a pattern copied out of somewhere else keeps working.\n */\n private parseGroup(): Node {\n const start = this.position;\n this.position += 1;\n\n if (this.source.startsWith('?:', this.position)) {\n this.position += 2;\n } else if (this.peek() === '?') {\n const named = /^\\?<([A-Za-z_$][\\w$]*)>/.exec(this.source.slice(this.position));\n if (named) {\n this.position += (named[0] as string).length;\n } else if (/^\\?(?:=|!|<=|<!)/.test(this.source.slice(this.position))) {\n throw new PatternError(\n 'lookaround is not supported: an automaton that cannot backtrack cannot look ahead - use ^= $= or *= for a fixed prefix, suffix or substring',\n start,\n );\n } else {\n throw new PatternError('unsupported group: expected (?:...) or (?<name>...)', start);\n }\n }\n\n const inner = this.parseAlternation();\n if (this.peek() !== ')') throw new PatternError('unmatched \"(\"', start);\n this.position += 1;\n return inner;\n }\n\n /**\n * Reads a `[...]` class.\n *\n * `[]` matches nothing and `[^]` matches anything, which reads like a mistake\n * and is what every JavaScript engine does: the class ends at the first `]`,\n * even when that `]` is the first character inside it.\n */\n private parseClass(): CharSet {\n const start = this.position;\n this.position += 1;\n const negated = this.peek() === '^';\n if (negated) this.position += 1;\n\n const ranges: Range[] = [];\n while (this.position < this.source.length && this.peek() !== ']') {\n const low = this.parseClassAtom();\n // A `-` between two single characters is a range. Anywhere else - at\n // either end of the class, or beside a `\\d`-style set, which has no\n // endpoint - it is a literal hyphen, exactly as Annex B has it.\n if (this.peek() !== '-' || this.source[this.position + 1] === ']' || this.position + 1 >= this.source.length) {\n push(ranges, low);\n continue;\n }\n const dash = this.position;\n this.position += 1;\n const high = this.parseClassAtom();\n if (typeof low === 'number' && typeof high === 'number') {\n if (low > high) throw new PatternError('characters out of order in a character class', dash);\n ranges.push([low, high]);\n continue;\n }\n push(ranges, low);\n ranges.push([0x2d, 0x2d]);\n push(ranges, high);\n }\n\n if (this.peek() !== ']') throw new PatternError('unterminated character class', start);\n this.position += 1;\n return { negated, ranges };\n }\n\n /** One member of a class: a code unit, or a whole set for `\\d` and its kind. */\n private parseClassAtom(): number | readonly Range[] {\n if (this.peek() !== '\\\\') {\n const code = (this.peek() as string).charCodeAt(0);\n this.position += 1;\n return code;\n }\n // `\\b` is a backspace inside a class and a word boundary outside one, which\n // is the only place the two readings of an escape diverge.\n if (this.source[this.position + 1] === 'b') {\n this.position += 2;\n return 0x08;\n }\n if (this.source[this.position + 1] === 'B') {\n throw new PatternError('\"\\\\B\" is an assertion, not a character, so it cannot be in a class', this.position);\n }\n const set = this.parseCharacterEscape();\n if (!set.negated && set.ranges.length === 1) {\n const [low, high] = set.ranges[0] as Range;\n if (low === high) return low;\n }\n return set.negated ? invert(set.ranges) : set.ranges;\n }\n\n /** An escape outside a class, where `\\b` and `\\B` are assertions. */\n private parseEscape(): Node {\n const next = this.source[this.position + 1];\n if (next === 'b' || next === 'B') {\n this.position += 2;\n return { kind: 'assert', assertion: next === 'b' ? 'word-boundary' : 'not-word-boundary' };\n }\n return { kind: 'char', set: this.parseCharacterEscape() };\n }\n\n /** Every escape that stands for a character or a set of them. */\n private parseCharacterEscape(): CharSet {\n const start = this.position;\n this.position += 1;\n const char = this.peek();\n if (char === undefined) throw new PatternError('pattern ends with a backslash', start);\n this.position += 1;\n\n switch (char) {\n case 'd':\n return { negated: false, ranges: DIGIT };\n case 'D':\n return { negated: true, ranges: DIGIT };\n case 'w':\n return { negated: false, ranges: WORD };\n case 'W':\n return { negated: true, ranges: WORD };\n case 's':\n return { negated: false, ranges: SPACE };\n case 'S':\n return { negated: true, ranges: SPACE };\n case 'n':\n return literal(0x0a);\n case 'r':\n return literal(0x0d);\n case 't':\n return literal(0x09);\n case 'f':\n return literal(0x0c);\n case 'v':\n return literal(0x0b);\n case '0':\n if (/^\\d/.test(this.source.slice(this.position))) {\n throw new PatternError('an octal escape is not supported - write \\\\xHH or \\\\uHHHH', start);\n }\n return literal(0);\n case 'x':\n return literal(this.readHex(2, start));\n case 'u':\n return literal(this.readHex(4, start));\n case 'c': {\n const letter = this.peek();\n if (letter === undefined || !/[A-Za-z]/.test(letter)) {\n throw new PatternError('expected a letter after \"\\\\c\"', start);\n }\n this.position += 1;\n return literal(letter.charCodeAt(0) % 32);\n }\n case 'k':\n throw new PatternError(\n 'a named backreference is not supported: a backreference is not a regular expression, and this is an automaton',\n start,\n );\n case 'p':\n case 'P':\n throw new PatternError(\n `\"\\\\${char}\" needs a table of Unicode properties, which this matcher does not carry - write the characters out as a [class]`,\n start,\n );\n default:\n if (/[1-9]/.test(char)) {\n throw new PatternError(\n 'a backreference is not supported: it is not a regular expression, and this is an automaton',\n start,\n );\n }\n if (/[A-Za-z]/.test(char)) {\n // `RegExp` reads an unknown letter escape as the letter itself, so\n // `\\A` quietly matches a capital A and `\\z` a lower-case z. Saying so\n // is worth more than agreeing with a rule nobody wanted.\n throw new PatternError(`unknown escape \"\\\\${char}\"`, start);\n }\n return literal(char.charCodeAt(0));\n }\n }\n\n private readHex(digits: number, start: number): number {\n const raw = this.source.slice(this.position, this.position + digits);\n if (raw.length !== digits || !/^[0-9a-fA-F]+$/.test(raw)) {\n throw new PatternError(`expected ${digits} hex digits after \"\\\\${this.source[start + 1] as string}\"`, start);\n }\n this.position += digits;\n return Number.parseInt(raw, 16);\n }\n\n private peek(): string | undefined {\n return this.source[this.position];\n }\n}\n\nfunction literal(code: number): CharSet {\n return { negated: false, ranges: [[code, code]] };\n}\n\nfunction push(ranges: Range[], atom: number | readonly Range[]): void {\n if (typeof atom === 'number') ranges.push([atom, atom]);\n else ranges.push(...atom);\n}\n\n/**\n * Complement of a range list, so `[\\D]` can sit inside a class.\n *\n * A negated escape is a set with no endpoints, and a class is a union of\n * ranges, so the only way to put one inside the other is to spell out what it\n * leaves.\n */\nfunction invert(ranges: readonly Range[]): readonly Range[] {\n const sorted = [...ranges].sort((a, b) => a[0] - b[0]);\n const out: Range[] = [];\n let cursor = 0;\n for (const [low, high] of sorted) {\n if (low > cursor) out.push([cursor, low - 1]);\n cursor = Math.max(cursor, high + 1);\n }\n if (cursor <= 0xffff) out.push([cursor, 0xffff]);\n return out;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Compilation */\n/* -------------------------------------------------------------------------- */\n\ninterface Split {\n readonly op: 'split';\n /** Where the first branch starts. */\n x: number;\n /** Where the second branch starts. */\n y: number;\n}\n\ninterface Jump {\n readonly op: 'jump';\n to: number;\n}\n\ntype Instruction =\n | { readonly op: 'char'; readonly set: CharSet }\n | Split\n | Jump\n | { readonly op: 'assert'; readonly assertion: Assertion }\n | { readonly op: 'match' };\n\nclass Compiler {\n readonly code: Instruction[] = [];\n\n private add<T extends Instruction>(instruction: T): T {\n if (this.code.length >= MAX_PROGRAM) {\n throw new PatternError(\n `pattern is too large: counted repetition is compiled by copying, and this needs more than ${MAX_PROGRAM} states`,\n 0,\n );\n }\n this.code.push(instruction);\n return instruction;\n }\n\n get here(): number {\n return this.code.length;\n }\n\n emitMatch(): void {\n this.add({ op: 'match' });\n }\n\n compile(node: Node): void {\n switch (node.kind) {\n case 'empty':\n return;\n case 'char':\n this.add({ op: 'char', set: node.set });\n return;\n case 'assert':\n this.add({ op: 'assert', assertion: node.assertion });\n return;\n case 'concat':\n for (const part of node.parts) this.compile(part);\n return;\n case 'alternate': {\n // One split per option but the last. Each split falls through to its\n // own branch and points its second arm at the next split; each branch\n // ends in a jump past all of them.\n const ends: Jump[] = [];\n for (let i = 0; i < node.options.length - 1; i += 1) {\n const split = this.add({ op: 'split', x: 0, y: 0 });\n split.x = this.here;\n this.compile(node.options[i] as Node);\n ends.push(this.add({ op: 'jump', to: 0 }));\n split.y = this.here;\n }\n this.compile(node.options[node.options.length - 1] as Node);\n for (const end of ends) end.to = this.here;\n return;\n }\n case 'repeat':\n this.repeat(node.node, node.min, node.max);\n return;\n }\n }\n\n private repeat(node: Node, min: number, max: number): void {\n for (let i = 0; i < min; i += 1) this.compile(node);\n\n if (max === Infinity) {\n const split = this.add({ op: 'split', x: 0, y: 0 });\n const body = this.here;\n split.x = body;\n this.compile(node);\n this.add({ op: 'jump', to: body - 1 });\n split.y = this.here;\n return;\n }\n\n // `{2,5}` is two copies and then three optional ones, each able to leave\n // for the far end rather than for the next copy.\n const exits: Split[] = [];\n for (let i = min; i < max; i += 1) {\n const split = this.add({ op: 'split', x: 0, y: 0 });\n split.x = this.here;\n exits.push(split);\n this.compile(node);\n }\n for (const split of exits) split.y = this.here;\n }\n}\n\n/* -------------------------------------------------------------------------- */\n/* Simulation */\n/* -------------------------------------------------------------------------- */\n\n/** A compiled pattern. Immutable, reusable, and safe to cache. */\nexport interface Matcher {\n /** True when the pattern matches anywhere in the subject. */\n test(subject: string): boolean;\n /** State count. Published for the size test, and for nothing else. */\n readonly size: number;\n}\n\n/**\n * Compiles a pattern into a matcher.\n *\n * Throws {@link PatternError} on anything it cannot run in linear time, which\n * is the point: the alternative to a message here is a build that stops.\n */\nexport function compilePattern(source: string): Matcher {\n const tree = new PatternParser(source).parse();\n const compiler = new Compiler();\n compiler.compile(tree);\n compiler.emitMatch();\n const code: readonly Instruction[] = compiler.code;\n // A pattern that begins by asserting the start of the subject cannot match\n // anywhere else, so the simulation stops seeding new threads at every\n // position. Nothing depends on this being noticed - it is the difference\n // between one pass and two over a long body.\n const anchored = startsAnchored(tree);\n\n return {\n size: code.length,\n test: (subject: string): boolean => run(code, subject, anchored),\n };\n}\n\n/** True when every path through the pattern opens by asserting the start. */\nfunction startsAnchored(node: Node): boolean {\n switch (node.kind) {\n case 'assert':\n return node.assertion === 'start';\n case 'concat': {\n const first = node.parts[0];\n return first !== undefined && startsAnchored(first);\n }\n case 'alternate':\n return node.options.every((option) => startsAnchored(option));\n case 'repeat':\n return node.min > 0 && startsAnchored(node.node);\n default:\n return false;\n }\n}\n\nfunction run(code: readonly Instruction[], subject: string, anchored: boolean): boolean {\n const length = subject.length;\n // The position each state was last reached at. One visit per state per\n // position is exactly what turns the exponent into a product.\n const visited = new Int32Array(code.length).fill(-1);\n let live: number[] = [];\n\n for (let position = 0; position <= length; position += 1) {\n if (position === 0 || !anchored) {\n if (seedFrom(code, visited, live, 0, subject, position)) return true;\n } else if (live.length === 0) {\n // An anchored pattern gets one chance, and every thread from it has died.\n return false;\n }\n\n if (position === length) return false;\n const char = subject.charCodeAt(position);\n const next: number[] = [];\n for (const pc of live) {\n const instruction = code[pc] as Instruction;\n if (instruction.op !== 'char' || !accepts(instruction.set, char)) continue;\n if (seedFrom(code, visited, next, pc + 1, subject, position + 1)) return true;\n }\n live = next;\n }\n\n return false;\n}\n\n/**\n * Follows every zero-width transition out of one state.\n *\n * Returns true the moment a thread reaches the end of the pattern: the only\n * question is whether a match exists, so there is no leftmost-longest to settle\n * and no captures to keep, and the first thread to arrive is the answer.\n */\nfunction seedFrom(\n code: readonly Instruction[],\n visited: Int32Array,\n list: number[],\n start: number,\n subject: string,\n position: number,\n): boolean {\n const stack: number[] = [start];\n while (stack.length > 0) {\n const pc = stack.pop() as number;\n if (visited[pc] === position) continue;\n visited[pc] = position;\n const instruction = code[pc] as Instruction;\n switch (instruction.op) {\n case 'match':\n return true;\n case 'jump':\n stack.push(instruction.to);\n break;\n case 'split':\n stack.push(instruction.y, instruction.x);\n break;\n case 'assert':\n if (holds(instruction.assertion, subject, position)) stack.push(pc + 1);\n break;\n case 'char':\n list.push(pc);\n break;\n }\n }\n return false;\n}\n\nfunction holds(assertion: Assertion, subject: string, position: number): boolean {\n switch (assertion) {\n case 'start':\n return position === 0;\n case 'end':\n return position === subject.length;\n default: {\n const before = position > 0 && isWordChar(subject.charCodeAt(position - 1));\n const after = position < subject.length && isWordChar(subject.charCodeAt(position));\n return (before !== after) === (assertion === 'word-boundary');\n }\n }\n}\n"]}
1
+ {"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pF,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,SAAS,KAAK,eAAe,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * A regular-expression matcher that cannot backtrack.\n *\n * `~=` is the one predicate in the selector language that used to hand a\n * user-supplied string to `RegExp` and wait. That is tolerable at a prompt,\n * where a human can press Ctrl-C. It is not tolerable in `.spec-graph.json`,\n * where the same string runs unattended in CI against every node in the corpus.\n *\n * The cost is neither theoretical nor exotic. `^([A-Za-z0-9_]+[ ]?)+$` is what\n * somebody writes to say \"the title is words separated by single spaces\", and\n * against a title that does not match, V8 tries one branch per way of cutting\n * each word into pieces:\n *\n * ```text\n * RegExp here\n * the quick brown fox jumps over the lazy dog! 0.9s 11us\n * the quick brown fox jumps over the lazy dog and! 5.4s 12us\n * the quick brown fox jumps over the lazy dog and keeps! 103s 13us\n * ```\n *\n * Each word of k letters can be cut into pieces 2^(k-1) ways, and the engine\n * tries the product of those, which is why adding one five-letter word costs\n * another factor of sixteen. A sixty-character title does not finish this year.\n *\n * So a pattern here is compiled to a **non-deterministic finite automaton** and\n * simulated over the subject one character at a time (Thompson, 1968), keeping\n * a set of live states instead of a stack of choices. Each state is visited at\n * most once per position, which makes the work exactly O(pattern x subject):\n * the right-hand column above, growing with the subject and not with the\n * pattern's ambiguity.\n *\n * What it costs is a dialect. Backreferences and lookaround are not regular and\n * have no place in a linear automaton, so they are **rejected while compiling**,\n * with a message and an offset, rather than accepted and then slow. That is the\n * whole trade: a predicate that finishes, against a short list of constructs\n * that a documentation selector never needed.\n *\n * Matching is unanchored and, by default, case-insensitive, because that is\n * what `~=` has always been - `new RegExp(source, 'i')` and `.test()`. Globs\n * compile to this as well, and a path on a case-sensitive filesystem needs the\n * case respected, which is the one option. There are no capture groups at all:\n * nothing asks where the match was, only whether there was one, which is why\n * this is a plain NFA simulation rather than a Pike VM.\n *\n * See ADR-0017.\n */\n\n/* -------------------------------------------------------------------------- */\n/* Errors */\n/* -------------------------------------------------------------------------- */\n\n/** A pattern that will not compile, and where in it the problem starts. */\nexport class PatternError extends Error {\n /** Offset into the pattern source. */\n readonly offset: number;\n\n constructor(message: string, offset: number) {\n super(message);\n this.name = 'PatternError';\n this.offset = offset;\n }\n}\n\n/**\n * Ceiling on the compiled program.\n *\n * Counted repetition is compiled by copying - `(ab){20}` is twenty copies -\n * which is part of what keeps the simulation flat, and also what makes\n * `(a{99}){99}` into ten thousand states. The bound has to live somewhere, and\n * a number checked while compiling is the only place it can be enforced without\n * measuring anything at match time.\n *\n * Far above any real selector: the widest pattern in this repository's own\n * tests compiles to seventeen states.\n */\nconst MAX_PROGRAM = 4096;\n\n/* -------------------------------------------------------------------------- */\n/* Character sets */\n/* -------------------------------------------------------------------------- */\n\n/** An inclusive range of UTF-16 code units. */\ntype Range = readonly [number, number];\n\n/**\n * A set of code units, as inclusive ranges.\n *\n * Code units rather than code points, because that is what a `RegExp` without\n * the `u` flag matches: `.` consumes one half of a surrogate pair, and so does\n * this. Agreeing with the engine this replaced matters more than being right\n * about astral planes, which no selector in any corpus has asked about.\n */\ninterface CharSet {\n readonly negated: boolean;\n readonly ranges: readonly Range[];\n}\n\n/** `.` - anything but a line terminator, which is the default `RegExp` reading. */\nconst DOT: CharSet = { negated: true, ranges: [[0x0a, 0x0a], [0x0d, 0x0d], [0x2028, 0x2029]] };\nconst DIGIT: readonly Range[] = [[0x30, 0x39]];\nconst WORD: readonly Range[] = [\n [0x30, 0x39],\n [0x41, 0x5a],\n [0x5f, 0x5f],\n [0x61, 0x7a],\n];\n/** `\\s`, taken from the specification rather than guessed at. */\nconst SPACE: readonly Range[] = [\n [0x09, 0x0d],\n [0x20, 0x20],\n [0xa0, 0xa0],\n [0x1680, 0x1680],\n [0x2000, 0x200a],\n [0x2028, 0x2029],\n [0x202f, 0x202f],\n [0x205f, 0x205f],\n [0x3000, 0x3000],\n [0xfeff, 0xfeff],\n];\n\n/**\n * Folds a code unit the way a case-insensitive `RegExp` does.\n *\n * This is `Canonicalize` from the language specification, non-Unicode mode:\n * upper-case the character, keep it unchanged if that produced anything other\n * than one code unit, and keep it unchanged if upper-casing dragged a\n * non-ASCII character into ASCII. The last clause is the one nobody expects and\n * the reason U+017F (long s) does not match `s`.\n */\nfunction canonical(code: number): number {\n // Every subject a glob sees is mostly ASCII, where the answer needs no string.\n // The general path below gives the same answer here, only slower.\n if (code < 128) return code >= 97 && code <= 122 ? code - 32 : code;\n const upper = String.fromCharCode(code).toUpperCase();\n if (upper.length !== 1) return code;\n const folded = upper.charCodeAt(0);\n if (code >= 128 && folded < 128) return code;\n return folded;\n}\n\n/**\n * Whether a set accepts a code unit, case-insensitively.\n *\n * The specification canonicalises both sides: a character matches a set when\n * *some* member of the set folds to the same thing it does. A single-character\n * member can be asked that exactly. A range cannot without a fold table for\n * every code unit, so a range is asked the question backwards - does the\n * character, or either of its own case forms, fall inside it - which is exact\n * for every character whose fold is its own case change, and therefore for\n * every range anyone has written.\n */\nfunction accepts(set: CharSet, code: number): boolean {\n const folded = canonical(code);\n let hit = false;\n for (let i = 0; i < set.ranges.length; i += 1) {\n const [low, high] = set.ranges[i] as Range;\n if (low === high ? low === code || canonical(low) === folded : inRange(low, high, code)) {\n hit = true;\n break;\n }\n }\n return set.negated ? !hit : hit;\n}\n\n/**\n * Whether some member of a range folds to the same thing a code unit does.\n *\n * Asked backwards, by trying the character's own case forms against the raw\n * range - and then checking that the form found there really does fold to the\n * same place, which is the part that is easy to leave out. U+017F upper-cases\n * to `S`, so without that check it matches `[A-Z]`, and it must not: the fold\n * keeps it outside ASCII, which is the same clause `isWordChar` gets wrong if\n * nobody is watching. The differential corpus caught both.\n */\nfunction inRange(low: number, high: number, code: number): boolean {\n if (code >= low && code <= high) return true;\n // An ASCII character's only other case form is its ASCII letter twin, and the\n // two always fold together - so the loop below would ask exactly this.\n if (code < 128) {\n const twin = code >= 65 && code <= 90 ? code + 32 : code >= 97 && code <= 122 ? code - 32 : -1;\n return twin >= low && twin <= high;\n }\n const folded = canonical(code);\n const char = String.fromCharCode(code);\n for (const variant of [char.toLowerCase(), char.toUpperCase()]) {\n if (variant.length !== 1) continue;\n const candidate = variant.charCodeAt(0);\n if (candidate >= low && candidate <= high && canonical(candidate) === folded) return true;\n }\n return false;\n}\n\n/**\n * Whether a set accepts a code unit as written.\n *\n * What `RegExp` does without the `i` flag, and so none of the folding above\n * applies - which also means none of its one divergence does.\n */\nfunction acceptsExactly(set: CharSet, code: number): boolean {\n return within(set.ranges, code) !== set.negated;\n}\n\nfunction within(ranges: readonly Range[], code: number): boolean {\n for (let i = 0; i < ranges.length; i += 1) {\n const range = ranges[i] as Range;\n if (code >= range[0] && code <= range[1]) return true;\n }\n return false;\n}\n\n/**\n * Word characters for `\\b`, which is exactly `\\w` here.\n *\n * The specification does widen this set under case-insensitivity - to every\n * character that folds into it, which is U+017F (long s) and U+212A (the\n * Kelvin sign) - but only in Unicode mode, where `Canonicalize` has no clause\n * keeping a non-ASCII character out of ASCII. This is the non-Unicode dialect,\n * so both stay outside and the table for `\\w` answers for `\\b` as well.\n *\n * Written down because the first version of this function widened the set, and\n * the differential test against `RegExp` is what said otherwise. Reading the\n * clause was not enough; running it was. See ADR-0017.\n */\nfunction isWordChar(code: number): boolean {\n return within(WORD, code);\n}\n\n/* -------------------------------------------------------------------------- */\n/* Syntax tree */\n/* -------------------------------------------------------------------------- */\n\ntype Assertion = 'start' | 'end' | 'word-boundary' | 'not-word-boundary';\n\ntype Node =\n | { readonly kind: 'empty' }\n | { readonly kind: 'char'; readonly set: CharSet }\n | { readonly kind: 'assert'; readonly assertion: Assertion }\n | { readonly kind: 'concat'; readonly parts: readonly Node[] }\n | { readonly kind: 'alternate'; readonly options: readonly Node[] }\n | { readonly kind: 'repeat'; readonly node: Node; readonly min: number; readonly max: number };\n\n/* -------------------------------------------------------------------------- */\n/* Parsing */\n/* -------------------------------------------------------------------------- */\n\nclass PatternParser {\n private readonly source: string;\n private position = 0;\n\n constructor(source: string) {\n this.source = source;\n }\n\n parse(): Node {\n const node = this.parseAlternation();\n // Every character is an atom except the two that close something, and\n // `parseSequence` stops on both, so anything left over is an unopened `)`.\n if (this.position < this.source.length) throw new PatternError('unmatched \")\"', this.position);\n return node;\n }\n\n private parseAlternation(): Node {\n const options: Node[] = [this.parseSequence()];\n while (this.peek() === '|') {\n this.position += 1;\n options.push(this.parseSequence());\n }\n return options.length === 1 ? (options[0] as Node) : { kind: 'alternate', options };\n }\n\n private parseSequence(): Node {\n const parts: Node[] = [];\n for (;;) {\n const char = this.peek();\n if (char === undefined || char === '|' || char === ')') break;\n parts.push(this.parseQuantified());\n }\n if (parts.length === 0) return { kind: 'empty' };\n return parts.length === 1 ? (parts[0] as Node) : { kind: 'concat', parts };\n }\n\n private parseQuantified(): Node {\n const start = this.position;\n // A group makes its contents quantifiable: `RegExp` rejects `\\b*` and\n // accepts `(\\b)*`, which is the same nothing said twice, and this parser\n // treats a group as transparent - so whether one was written is the only\n // thing left that distinguishes the two.\n const grouped = this.peek() === '(';\n const atom = this.parseAtom();\n const bounds = this.parseQuantifier();\n if (bounds === null) return atom;\n if (atom.kind === 'assert' && !grouped) {\n throw new PatternError('nothing to repeat: a quantifier cannot follow an anchor', start);\n }\n return { kind: 'repeat', node: atom, min: bounds.min, max: bounds.max };\n }\n\n /** `*`, `+`, `?`, `{n}`, `{n,}`, `{n,m}`, and a trailing `?` that is ignored. */\n private parseQuantifier(): { min: number; max: number } | null {\n const char = this.peek();\n let bounds: { min: number; max: number } | null = null;\n\n if (char === '*') bounds = { min: 0, max: Infinity };\n else if (char === '+') bounds = { min: 1, max: Infinity };\n else if (char === '?') bounds = { min: 0, max: 1 };\n\n if (bounds !== null) this.position += 1;\n else if (char === '{') bounds = this.parseBraces();\n if (bounds === null) return null;\n\n // Laziness decides *which* match is found, and nothing here asks: the\n // question is whether one exists, and a lazy quantifier accepts the same\n // language as a greedy one.\n if (this.peek() === '?') this.position += 1;\n return bounds;\n }\n\n /**\n * Reads `{n,m}`, or nothing.\n *\n * A `{` that does not open a counted repetition is a literal brace, which is\n * what `RegExp` does with `a{` and what any pattern written against a\n * document full of `{0}` placeholders depends on.\n */\n private parseBraces(): { min: number; max: number } | null {\n const match = /^\\{(\\d+)(?:(,)(\\d*))?\\}/.exec(this.source.slice(this.position));\n if (!match) return null;\n const min = Number(match[1]);\n const max = match[2] === undefined ? min : match[3] === '' ? Infinity : Number(match[3]);\n if (min > max) throw new PatternError('numbers out of order in a counted repetition', this.position);\n this.position += (match[0] as string).length;\n return { min, max };\n }\n\n private parseAtom(): Node {\n const start = this.position;\n const char = this.peek();\n\n switch (char) {\n case undefined:\n throw new PatternError('pattern ends where an expression was expected', start);\n case '(':\n return this.parseGroup();\n case '[':\n return { kind: 'char', set: this.parseClass() };\n case '.':\n this.position += 1;\n return { kind: 'char', set: DOT };\n case '^':\n this.position += 1;\n return { kind: 'assert', assertion: 'start' };\n case '$':\n this.position += 1;\n return { kind: 'assert', assertion: 'end' };\n case '*':\n case '+':\n throw new PatternError(`nothing to repeat before \"${char}\"`, start);\n case '\\\\':\n return this.parseEscape();\n default:\n this.position += 1;\n return { kind: 'char', set: literal(char.charCodeAt(0)) };\n }\n }\n\n /**\n * A group, which is never a capture.\n *\n * `(a)` and `(?:a)` compile to the same automaton because nothing downstream\n * can ask what `(a)` caught. A named group is accepted and its name dropped,\n * so a pattern copied out of somewhere else keeps working.\n */\n private parseGroup(): Node {\n const start = this.position;\n this.position += 1;\n\n if (this.source.startsWith('?:', this.position)) {\n this.position += 2;\n } else if (this.peek() === '?') {\n const named = /^\\?<([A-Za-z_$][\\w$]*)>/.exec(this.source.slice(this.position));\n if (named) {\n this.position += (named[0] as string).length;\n } else if (/^\\?(?:=|!|<=|<!)/.test(this.source.slice(this.position))) {\n throw new PatternError(\n 'lookaround is not supported: an automaton that cannot backtrack cannot look ahead - use ^= $= or *= for a fixed prefix, suffix or substring',\n start,\n );\n } else {\n throw new PatternError('unsupported group: expected (?:...) or (?<name>...)', start);\n }\n }\n\n const inner = this.parseAlternation();\n if (this.peek() !== ')') throw new PatternError('unmatched \"(\"', start);\n this.position += 1;\n return inner;\n }\n\n /**\n * Reads a `[...]` class.\n *\n * `[]` matches nothing and `[^]` matches anything, which reads like a mistake\n * and is what every JavaScript engine does: the class ends at the first `]`,\n * even when that `]` is the first character inside it.\n */\n private parseClass(): CharSet {\n const start = this.position;\n this.position += 1;\n const negated = this.peek() === '^';\n if (negated) this.position += 1;\n\n const ranges: Range[] = [];\n while (this.position < this.source.length && this.peek() !== ']') {\n const low = this.parseClassAtom();\n // A `-` between two single characters is a range. Anywhere else - at\n // either end of the class, or beside a `\\d`-style set, which has no\n // endpoint - it is a literal hyphen, exactly as Annex B has it.\n if (this.peek() !== '-' || this.source[this.position + 1] === ']' || this.position + 1 >= this.source.length) {\n push(ranges, low);\n continue;\n }\n const dash = this.position;\n this.position += 1;\n const high = this.parseClassAtom();\n if (typeof low === 'number' && typeof high === 'number') {\n if (low > high) throw new PatternError('characters out of order in a character class', dash);\n ranges.push([low, high]);\n continue;\n }\n push(ranges, low);\n ranges.push([0x2d, 0x2d]);\n push(ranges, high);\n }\n\n if (this.peek() !== ']') throw new PatternError('unterminated character class', start);\n this.position += 1;\n return { negated, ranges };\n }\n\n /** One member of a class: a code unit, or a whole set for `\\d` and its kind. */\n private parseClassAtom(): number | readonly Range[] {\n if (this.peek() !== '\\\\') {\n const code = (this.peek() as string).charCodeAt(0);\n this.position += 1;\n return code;\n }\n // `\\b` is a backspace inside a class and a word boundary outside one, which\n // is the only place the two readings of an escape diverge.\n if (this.source[this.position + 1] === 'b') {\n this.position += 2;\n return 0x08;\n }\n if (this.source[this.position + 1] === 'B') {\n throw new PatternError('\"\\\\B\" is an assertion, not a character, so it cannot be in a class', this.position);\n }\n const set = this.parseCharacterEscape();\n if (!set.negated && set.ranges.length === 1) {\n const [low, high] = set.ranges[0] as Range;\n if (low === high) return low;\n }\n return set.negated ? invert(set.ranges) : set.ranges;\n }\n\n /** An escape outside a class, where `\\b` and `\\B` are assertions. */\n private parseEscape(): Node {\n const next = this.source[this.position + 1];\n if (next === 'b' || next === 'B') {\n this.position += 2;\n return { kind: 'assert', assertion: next === 'b' ? 'word-boundary' : 'not-word-boundary' };\n }\n return { kind: 'char', set: this.parseCharacterEscape() };\n }\n\n /** Every escape that stands for a character or a set of them. */\n private parseCharacterEscape(): CharSet {\n const start = this.position;\n this.position += 1;\n const char = this.peek();\n if (char === undefined) throw new PatternError('pattern ends with a backslash', start);\n this.position += 1;\n\n switch (char) {\n case 'd':\n return { negated: false, ranges: DIGIT };\n case 'D':\n return { negated: true, ranges: DIGIT };\n case 'w':\n return { negated: false, ranges: WORD };\n case 'W':\n return { negated: true, ranges: WORD };\n case 's':\n return { negated: false, ranges: SPACE };\n case 'S':\n return { negated: true, ranges: SPACE };\n case 'n':\n return literal(0x0a);\n case 'r':\n return literal(0x0d);\n case 't':\n return literal(0x09);\n case 'f':\n return literal(0x0c);\n case 'v':\n return literal(0x0b);\n case '0':\n if (/^\\d/.test(this.source.slice(this.position))) {\n throw new PatternError('an octal escape is not supported - write \\\\xHH or \\\\uHHHH', start);\n }\n return literal(0);\n case 'x':\n return literal(this.readHex(2, start));\n case 'u':\n return literal(this.readHex(4, start));\n case 'c': {\n const letter = this.peek();\n if (letter === undefined || !/[A-Za-z]/.test(letter)) {\n throw new PatternError('expected a letter after \"\\\\c\"', start);\n }\n this.position += 1;\n return literal(letter.charCodeAt(0) % 32);\n }\n case 'k':\n throw new PatternError(\n 'a named backreference is not supported: a backreference is not a regular expression, and this is an automaton',\n start,\n );\n case 'p':\n case 'P':\n throw new PatternError(\n `\"\\\\${char}\" needs a table of Unicode properties, which this matcher does not carry - write the characters out as a [class]`,\n start,\n );\n default:\n if (/[1-9]/.test(char)) {\n throw new PatternError(\n 'a backreference is not supported: it is not a regular expression, and this is an automaton',\n start,\n );\n }\n if (/[A-Za-z]/.test(char)) {\n // `RegExp` reads an unknown letter escape as the letter itself, so\n // `\\A` quietly matches a capital A and `\\z` a lower-case z. Saying so\n // is worth more than agreeing with a rule nobody wanted.\n throw new PatternError(`unknown escape \"\\\\${char}\"`, start);\n }\n return literal(char.charCodeAt(0));\n }\n }\n\n private readHex(digits: number, start: number): number {\n const raw = this.source.slice(this.position, this.position + digits);\n if (raw.length !== digits || !/^[0-9a-fA-F]+$/.test(raw)) {\n throw new PatternError(`expected ${digits} hex digits after \"\\\\${this.source[start + 1] as string}\"`, start);\n }\n this.position += digits;\n return Number.parseInt(raw, 16);\n }\n\n private peek(): string | undefined {\n return this.source[this.position];\n }\n}\n\nfunction literal(code: number): CharSet {\n return { negated: false, ranges: [[code, code]] };\n}\n\nfunction push(ranges: Range[], atom: number | readonly Range[]): void {\n if (typeof atom === 'number') ranges.push([atom, atom]);\n else ranges.push(...atom);\n}\n\n/**\n * Complement of a range list, so `[\\D]` can sit inside a class.\n *\n * A negated escape is a set with no endpoints, and a class is a union of\n * ranges, so the only way to put one inside the other is to spell out what it\n * leaves.\n */\nfunction invert(ranges: readonly Range[]): readonly Range[] {\n const sorted = [...ranges].sort((a, b) => a[0] - b[0]);\n const out: Range[] = [];\n let cursor = 0;\n for (const [low, high] of sorted) {\n if (low > cursor) out.push([cursor, low - 1]);\n cursor = Math.max(cursor, high + 1);\n }\n if (cursor <= 0xffff) out.push([cursor, 0xffff]);\n return out;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Compilation */\n/* -------------------------------------------------------------------------- */\n\ninterface Split {\n readonly op: 'split';\n /** Where the first branch starts. */\n x: number;\n /** Where the second branch starts. */\n y: number;\n}\n\ninterface Jump {\n readonly op: 'jump';\n to: number;\n}\n\ntype Instruction =\n | { readonly op: 'char'; readonly set: CharSet }\n | Split\n | Jump\n | { readonly op: 'assert'; readonly assertion: Assertion }\n | { readonly op: 'match' };\n\nclass Compiler {\n readonly code: Instruction[] = [];\n\n private add<T extends Instruction>(instruction: T): T {\n if (this.code.length >= MAX_PROGRAM) {\n throw new PatternError(\n `pattern is too large: counted repetition is compiled by copying, and this needs more than ${MAX_PROGRAM} states`,\n 0,\n );\n }\n this.code.push(instruction);\n return instruction;\n }\n\n get here(): number {\n return this.code.length;\n }\n\n emitMatch(): void {\n this.add({ op: 'match' });\n }\n\n compile(node: Node): void {\n switch (node.kind) {\n case 'empty':\n return;\n case 'char':\n this.add({ op: 'char', set: node.set });\n return;\n case 'assert':\n this.add({ op: 'assert', assertion: node.assertion });\n return;\n case 'concat':\n for (const part of node.parts) this.compile(part);\n return;\n case 'alternate': {\n // One split per option but the last. Each split falls through to its\n // own branch and points its second arm at the next split; each branch\n // ends in a jump past all of them.\n const ends: Jump[] = [];\n for (let i = 0; i < node.options.length - 1; i += 1) {\n const split = this.add({ op: 'split', x: 0, y: 0 });\n split.x = this.here;\n this.compile(node.options[i] as Node);\n ends.push(this.add({ op: 'jump', to: 0 }));\n split.y = this.here;\n }\n this.compile(node.options[node.options.length - 1] as Node);\n for (const end of ends) end.to = this.here;\n return;\n }\n case 'repeat':\n this.repeat(node.node, node.min, node.max);\n return;\n }\n }\n\n private repeat(node: Node, min: number, max: number): void {\n for (let i = 0; i < min; i += 1) this.compile(node);\n\n if (max === Infinity) {\n const split = this.add({ op: 'split', x: 0, y: 0 });\n const body = this.here;\n split.x = body;\n this.compile(node);\n this.add({ op: 'jump', to: body - 1 });\n split.y = this.here;\n return;\n }\n\n // `{2,5}` is two copies and then three optional ones, each able to leave\n // for the far end rather than for the next copy.\n const exits: Split[] = [];\n for (let i = min; i < max; i += 1) {\n const split = this.add({ op: 'split', x: 0, y: 0 });\n split.x = this.here;\n exits.push(split);\n this.compile(node);\n }\n for (const split of exits) split.y = this.here;\n }\n}\n\n/* -------------------------------------------------------------------------- */\n/* Simulation */\n/* -------------------------------------------------------------------------- */\n\n/**\n * A compiled pattern. Reusable and safe to cache.\n *\n * Not reentrant, which nothing can ask of it: `test` is synchronous and calls\n * out to nothing, and the buffers it keeps between subjects are what make it\n * cheap enough to run against every path a walk visits.\n */\nexport interface Matcher {\n /** True when the pattern matches anywhere in the subject. */\n test(subject: string): boolean;\n /** State count. Published for the size test, and for nothing else. */\n readonly size: number;\n}\n\nexport interface PatternOptions {\n /** Fold case the way the `i` flag does. On unless set to `false`. */\n readonly ignoreCase?: boolean | undefined;\n}\n\n/**\n * Compiles a pattern into a matcher.\n *\n * Throws {@link PatternError} on anything it cannot run in linear time, which\n * is the point: the alternative to a message here is a build that stops.\n */\nexport function compilePattern(source: string, options: PatternOptions = {}): Matcher {\n const tree = new PatternParser(source).parse();\n const compiler = new Compiler();\n compiler.compile(tree);\n compiler.emitMatch();\n // A pattern that begins by asserting the start of the subject cannot match\n // anywhere else, so the simulation stops seeding new threads at every\n // position. Nothing depends on this being noticed - it is the difference\n // between one pass and two over a long body.\n const machine = new Machine(compiler.code, startsAnchored(tree), options.ignoreCase !== false);\n return {\n size: compiler.code.length,\n test: (subject: string): boolean => machine.test(subject),\n };\n}\n\n/** True when every path through the pattern opens by asserting the start. */\nfunction startsAnchored(node: Node): boolean {\n switch (node.kind) {\n case 'assert':\n return node.assertion === 'start';\n case 'concat': {\n const first = node.parts[0];\n return first !== undefined && startsAnchored(first);\n }\n case 'alternate':\n return node.options.every((option) => startsAnchored(option));\n case 'repeat':\n return node.min > 0 && startsAnchored(node.node);\n default:\n return false;\n }\n}\n\nconst OP_CHAR = 0;\nconst OP_SPLIT = 1;\nconst OP_JUMP = 2;\nconst OP_ASSERT = 3;\nconst OP_MATCH = 4;\n\n/** Fills the slots of states that are not characters, where nothing reads it. */\nconst NOTHING: CharSet = { negated: false, ranges: [] };\n\n/**\n * The simulation, over the program flattened into typed arrays.\n *\n * The compiler's instructions are objects of five shapes, and one loop reading\n * `op` off all five is a megamorphic property read on every step. Simulated that\n * way, with a fresh visited table per subject, a glob cost about 3.5\n * microseconds a path and a path that failed on its first character still paid\n * half a microsecond for the allocation. Flat arrays and buffers kept between\n * subjects bring those to 0.6 and 0.04 - `RegExp` takes 0.06 - which matters\n * because a walk tests every path it visits against every pattern.\n */\nclass Machine {\n private readonly ops: Uint8Array;\n /** A split's first branch, or a jump's target. */\n private readonly first: Int32Array;\n /** A split's second branch. */\n private readonly second: Int32Array;\n private readonly sets: CharSet[];\n private readonly assertions: Assertion[];\n private readonly anchored: boolean;\n private readonly ignoreCase: boolean;\n\n /**\n * The position each state was last reached at. One visit per state per\n * position is exactly what turns the exponent into a product.\n */\n private readonly visited: Int32Array;\n /** Each visit pushes at most two states, so this cannot overflow. */\n private readonly stack: Int32Array;\n private live: Int32Array;\n private next: Int32Array;\n\n constructor(code: readonly Instruction[], anchored: boolean, ignoreCase: boolean) {\n const size = code.length;\n this.ops = new Uint8Array(size);\n this.first = new Int32Array(size);\n this.second = new Int32Array(size);\n this.sets = new Array<CharSet>(size).fill(NOTHING);\n this.assertions = new Array<Assertion>(size).fill('start');\n this.anchored = anchored;\n this.ignoreCase = ignoreCase;\n this.visited = new Int32Array(size).fill(-1);\n this.stack = new Int32Array(2 * size + 1);\n this.live = new Int32Array(size);\n this.next = new Int32Array(size);\n\n code.forEach((instruction, pc) => {\n switch (instruction.op) {\n case 'char':\n this.ops[pc] = OP_CHAR;\n this.sets[pc] = instruction.set;\n break;\n case 'split':\n this.ops[pc] = OP_SPLIT;\n this.first[pc] = instruction.x;\n this.second[pc] = instruction.y;\n break;\n case 'jump':\n this.ops[pc] = OP_JUMP;\n this.first[pc] = instruction.to;\n break;\n case 'assert':\n this.ops[pc] = OP_ASSERT;\n this.assertions[pc] = instruction.assertion;\n break;\n case 'match':\n this.ops[pc] = OP_MATCH;\n break;\n }\n });\n }\n\n test(subject: string): boolean {\n const length = subject.length;\n this.visited.fill(-1);\n\n let live = this.live;\n let next = this.next;\n let alive = 0;\n\n for (let position = 0; position <= length; position += 1) {\n if (position === 0 || !this.anchored) {\n alive = this.seed(live, alive, 0, subject, position);\n if (alive < 0) return true;\n } else if (alive === 0) {\n // An anchored pattern gets one chance, and every thread from it has died.\n return false;\n }\n\n if (position === length) return false;\n const char = subject.charCodeAt(position);\n let arriving = 0;\n for (let i = 0; i < alive; i += 1) {\n const pc = live[i] as number;\n const set = this.sets[pc] as CharSet;\n if (!(this.ignoreCase ? accepts(set, char) : acceptsExactly(set, char))) continue;\n arriving = this.seed(next, arriving, pc + 1, subject, position + 1);\n if (arriving < 0) return true;\n }\n const spent = live;\n live = next;\n next = spent;\n alive = arriving;\n }\n\n return false;\n }\n\n /**\n * Follows every zero-width transition out of one state, appending the\n * character states it reaches to `list`.\n *\n * Returns the new length of the list, or -1 the moment a thread reaches the\n * end of the pattern: the only question is whether a match exists, so there\n * is no leftmost-longest to settle and no captures to keep, and the first\n * thread to arrive is the answer.\n *\n * A stray thread at state 0 changes no answer: an unanchored pattern seeds it\n * at every position anyway, and an anchored one opens by asserting the start.\n * That makes two mutants here equivalent, with no test to write - the loop\n * running once past an empty stack, and a jump read as a split, both of which\n * add exactly that thread.\n */\n private seed(list: Int32Array, length: number, start: number, subject: string, position: number): number {\n const { ops, first, second, visited, stack } = this;\n let count = length;\n let top = 0;\n stack[top++] = start;\n while (top > 0) {\n const pc = stack[--top] as number;\n if (visited[pc] === position) continue;\n visited[pc] = position;\n switch (ops[pc]) {\n case OP_MATCH:\n return -1;\n case OP_JUMP:\n stack[top++] = first[pc] as number;\n break;\n case OP_SPLIT:\n stack[top++] = second[pc] as number;\n stack[top++] = first[pc] as number;\n break;\n case OP_ASSERT:\n if (holds(this.assertions[pc] as Assertion, subject, position)) stack[top++] = pc + 1;\n break;\n default:\n list[count++] = pc;\n }\n }\n return count;\n }\n}\n\nfunction holds(assertion: Assertion, subject: string, position: number): boolean {\n switch (assertion) {\n case 'start':\n return position === 0;\n case 'end':\n return position === subject.length;\n default: {\n const before = position > 0 && isWordChar(subject.charCodeAt(position - 1));\n const after = position < subject.length && isWordChar(subject.charCodeAt(position));\n return (before !== after) === (assertion === 'word-boundary');\n }\n }\n}\n"]}
package/dist/report.d.ts CHANGED
@@ -127,6 +127,16 @@ export type GraphFormat = 'dot' | 'mermaid' | 'json';
127
127
  export interface GraphExportOptions {
128
128
  /** Leave out `contains` edges and item nodes. */
129
129
  readonly documentsOnly?: boolean | undefined;
130
+ /**
131
+ * What made the export, for the JSON form. Passed in rather than looked up,
132
+ * because reading the package's own version is I/O and this module has none.
133
+ * Two exports from different versions differ wherever extraction changed, and
134
+ * `diff` warns about that only if it can see it (ADR-0020).
135
+ */
136
+ readonly generator?: {
137
+ readonly name: string;
138
+ readonly version: string;
139
+ } | undefined;
130
140
  }
131
141
  /** Serialises the graph for Graphviz, Mermaid, or a downstream tool. */
132
142
  export declare function formatGraph(graph: SpecGraph, format: GraphFormat, options?: GraphExportOptions): string;
package/dist/report.js CHANGED
@@ -507,6 +507,7 @@ export function formatGraph(graph, format, options = {}) {
507
507
  case 'json':
508
508
  return `${JSON.stringify({
509
509
  version: 1,
510
+ ...(options.generator !== undefined && { generator: options.generator }),
510
511
  nodes: nodes.map(serialiseNode),
511
512
  edges: edges.map((edge) => ({
512
513
  kind: edge.kind,
@@ -545,6 +546,7 @@ function serialiseNode(node) {
545
546
  ? { ...base, path: node.path, phase: node.phase, status: node.rawStatus, aliases: node.aliases }
546
547
  : {
547
548
  ...base,
549
+ declared: node.declared,
548
550
  document: node.document,
549
551
  section: node.section,
550
552
  disposition: node.disposition,