parseman 0.61.0 → 0.61.2

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.
@@ -0,0 +1,41 @@
1
+ import { type CompactProgram, type TableProgram } from './program.ts';
2
+ import type { RunCfg } from './assemble.ts';
3
+ export type BacktrackCounts = {
4
+ rewinds: number;
5
+ bytesReread: number;
6
+ lookaheads: number;
7
+ lookaheadBytes: number;
8
+ regexLookarounds: number;
9
+ regexLookaroundBytes: number;
10
+ };
11
+ /** Does this pattern read input it does not consume? */
12
+ export declare function hasLookaround(re: RegExp): boolean;
13
+ /**
14
+ * The counters one probed parse writes. Shared by both table engines and the
15
+ * interpreter probe, so all three count by the same rule.
16
+ */
17
+ export declare class BacktrackRecorder {
18
+ input: string;
19
+ private counts;
20
+ private look;
21
+ private opaque;
22
+ private last;
23
+ private furthest;
24
+ begin(input: string): void;
25
+ /** The counts for the parse `begin` opened. Throws if a region was left open. */
26
+ end(): BacktrackCounts;
27
+ consume(start: number, end: number): void;
28
+ enterLookahead(): void;
29
+ exitLookahead(): void;
30
+ regexAttempt(): void;
31
+ regexMatch(re: RegExp, start: number, end: number): void;
32
+ /** A read whose inner steps are not the grammar's (the interpreter's scans). */
33
+ enterOpaque(): void;
34
+ exitOpaque(): void;
35
+ }
36
+ export declare function zeroCounts(): BacktrackCounts;
37
+ /** A copy of `source` whose terminals and lookaheads report to `rec`. */
38
+ export declare function probeProgram(source: TableProgram | CompactProgram, rec: BacktrackRecorder): TableProgram;
39
+ /** The option set a probe runs a program under: a plain parse of its host mode. */
40
+ export declare function probeCfg(prog: TableProgram): RunCfg;
41
+ //# sourceMappingURL=backtrack-probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backtrack-probe.d.ts","sourceRoot":"","sources":["../../src/table/backtrack-probe.ts"],"names":[],"mappings":"AAuEA,OAAO,EAC4B,KAAK,cAAc,EAAmB,KAAK,YAAY,EACzF,MAAM,cAAc,CAAA;AACrB,O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,GAAG,MAAM,CAEnD"}
@@ -24,5 +24,15 @@
24
24
  * report), `site-labels.ts` ignores it (an unwalked site resolves to `TOP` via
25
25
  * `labelAt`, and the enclosing assembly is unemittable anyway).
26
26
  */
27
+ /**
28
+ * The child instructions of the row at `ip`, read through `childSlotOffsets` below:
29
+ * one edge table, two views of it.
30
+ */
27
31
  export declare function childSlots(code: ArrayLike<number>, ip: number, out: number[]): boolean;
32
+ /**
33
+ * The OPERAND OFFSETS that hold child instructions — the edge table itself. A caller
34
+ * that rewrites a program's edges (`backtrack-probe.ts`) needs where an edge is
35
+ * stored, not only where it points.
36
+ */
37
+ export declare function childSlotOffsets(code: ArrayLike<number>, ip: number, out: number[]): boolean;
28
38
  //# sourceMappingURL=child-slots.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"child-slots.d.ts","sourceRoot":"","sources":["../../src/table/child-slots.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAiFtF"}
1
+ {"version":3,"file":"child-slots.d.ts","sourceRoot":"","sources":["../../src/table/child-slots.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAKtF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAiF5F"}
@@ -3628,7 +3628,7 @@ function regex(pattern, flags = "") {
3628
3628
  }
3629
3629
 
3630
3630
  // src/version.ts
3631
- var PARSEMAN_VERSION = "0.61.0";
3631
+ var PARSEMAN_VERSION = "0.61.2";
3632
3632
 
3633
3633
  // src/table/lex-body.ts
3634
3634
  function buildLexBodyRecognizer(spec, constants) {
@@ -6863,6 +6863,12 @@ function emitShapeMatch(shape, start, mint, ind, firstChar) {
6863
6863
 
6864
6864
  // src/table/child-slots.ts
6865
6865
  function childSlots(code, ip, out) {
6866
+ const from = out.length;
6867
+ if (!childSlotOffsets(code, ip, out)) return false;
6868
+ for (let i = from; i < out.length; i++) out[i] = code[out[i]];
6869
+ return true;
6870
+ }
6871
+ function childSlotOffsets(code, ip, out) {
6866
6872
  switch (code[ip]) {
6867
6873
  // ZERO-WIDTH / TERMINAL ROWS — no successor. `OP_GUARD` and `OP_ADJ` are both
6868
6874
  // childless tests. `OP_LIVE` holds a hand-written combinator in `prog.fns`; its
@@ -6895,7 +6901,7 @@ function childSlots(code, ip, out) {
6895
6901
  case OP_COV:
6896
6902
  case OP_REJECT:
6897
6903
  case OP_GAPGATE:
6898
- out.push(code[ip + 1]);
6904
+ out.push(ip + 1);
6899
6905
  return true;
6900
6906
  // Single child at `ip + 2`.
6901
6907
  case OP_GATE:
@@ -6912,55 +6918,55 @@ function childSlots(code, ip, out) {
6912
6918
  case OP_ARMGATE:
6913
6919
  case OP_RGATE:
6914
6920
  case OP_RGATE2:
6915
- out.push(code[ip + 2]);
6921
+ out.push(ip + 2);
6916
6922
  return true;
6917
6923
  // `STRICT strict tolerant` — both encodings are reachable; an assembly keeps one.
6918
6924
  case OP_STRICT:
6919
- out.push(code[ip + 1], code[ip + 2]);
6925
+ out.push(ip + 1, ip + 2);
6920
6926
  return true;
6921
6927
  // `ROUTED fallback` — the operand is an offset or −1. The routed token itself is
6922
6928
  // data the enclosing `dispatch()` already consumed, so the only edge is the
6923
6929
  // fallback.
6924
6930
  case OP_ROUTED:
6925
- if (code[ip + 1] >= 0) out.push(code[ip + 1]);
6931
+ if (code[ip + 1] >= 0) out.push(ip + 1);
6926
6932
  return true;
6927
6933
  // `DISPATCH sel d other otherRouted n a1 … an` — the SELECTOR is a child on
6928
6934
  // exactly the same footing as the arms: it runs inside whatever node and scope
6929
6935
  // this site sits in.
6930
6936
  case OP_DISPATCH: {
6931
- out.push(code[ip + 1]);
6932
- if (code[ip + 3] >= 0) out.push(code[ip + 3]);
6937
+ out.push(ip + 1);
6938
+ if (code[ip + 3] >= 0) out.push(ip + 3);
6933
6939
  const n = code[ip + 5];
6934
- for (let i = 0; i < n; i++) out.push(code[ip + 6 + i]);
6940
+ for (let i = 0; i < n; i++) out.push(ip + 6 + i);
6935
6941
  return true;
6936
6942
  }
6937
6943
  case OP_SEQ:
6938
6944
  case OP_SEQV: {
6939
6945
  const n = code[ip + 1];
6940
- for (let i = 0; i < n; i++) out.push(code[ip + 2 + i]);
6946
+ for (let i = 0; i < n; i++) out.push(ip + 2 + i);
6941
6947
  return true;
6942
6948
  }
6943
6949
  case OP_SEQX: {
6944
6950
  const n = code[ip + 2];
6945
- for (let i = 0; i < n; i++) out.push(code[ip + 3 + i]);
6951
+ for (let i = 0; i < n; i++) out.push(ip + 3 + i);
6946
6952
  return true;
6947
6953
  }
6948
6954
  case OP_CHOICE: {
6949
6955
  const n = code[ip + 2];
6950
- for (let i = 0; i < n; i++) out.push(code[ip + 4 + i]);
6956
+ for (let i = 0; i < n; i++) out.push(ip + 4 + i);
6951
6957
  return true;
6952
6958
  }
6953
6959
  // Arms are stride-2 from `ip + 4` — the gate word sits beside each arm offset.
6954
6960
  case OP_GREEDY: {
6955
- out.push(code[ip + 1]);
6961
+ out.push(ip + 1);
6956
6962
  const n = code[ip + 2];
6957
- for (let i = 0; i < n; i++) out.push(code[ip + 4 + 2 * i]);
6963
+ for (let i = 0; i < n; i++) out.push(ip + 4 + 2 * i);
6958
6964
  return true;
6959
6965
  }
6960
6966
  case OP_REP:
6961
6967
  case OP_REPV:
6962
- out.push(code[ip + 1]);
6963
- if (code[ip + 4] >= 0) out.push(code[ip + 4]);
6968
+ out.push(ip + 1);
6969
+ if (code[ip + 4] >= 0) out.push(ip + 4);
6964
6970
  return true;
6965
6971
  default:
6966
6972
  return false;