parseman 0.12.0 → 0.14.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 (42) hide show
  1. package/dist/combinators/expect.d.ts.map +1 -1
  2. package/dist/combinators/node.d.ts +1 -1
  3. package/dist/combinators/node.d.ts.map +1 -1
  4. package/dist/combinators/parser.d.ts.map +1 -1
  5. package/dist/combinators/regex-analyze.d.ts +6 -0
  6. package/dist/combinators/regex-analyze.d.ts.map +1 -0
  7. package/dist/combinators/regex.d.ts +16 -1
  8. package/dist/combinators/regex.d.ts.map +1 -1
  9. package/dist/compiler/build-arity.d.ts.map +1 -1
  10. package/dist/compiler/codegen.d.ts +45 -0
  11. package/dist/compiler/codegen.d.ts.map +1 -1
  12. package/dist/compiler/inline-build.d.ts.map +1 -1
  13. package/dist/compiler/linker.d.ts +44 -0
  14. package/dist/compiler/linker.d.ts.map +1 -0
  15. package/dist/compiler/scannable-run.d.ts +80 -2
  16. package/dist/compiler/scannable-run.d.ts.map +1 -1
  17. package/dist/cst/offset-model.d.ts +119 -0
  18. package/dist/cst/offset-model.d.ts.map +1 -0
  19. package/dist/cst/relative-spans.d.ts +56 -0
  20. package/dist/cst/relative-spans.d.ts.map +1 -0
  21. package/dist/cst/types.d.ts +1 -1
  22. package/dist/functional/doc.d.ts +26 -6
  23. package/dist/functional/doc.d.ts.map +1 -1
  24. package/dist/functional/run.d.ts +63 -0
  25. package/dist/functional/run.d.ts.map +1 -0
  26. package/dist/index.cjs +1613 -148
  27. package/dist/index.cjs.map +4 -4
  28. package/dist/index.d.ts +11 -3
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1613 -148
  31. package/dist/index.js.map +4 -4
  32. package/dist/plugin/evaluator.d.ts.map +1 -1
  33. package/dist/plugin/index.cjs +1520 -187
  34. package/dist/plugin/index.cjs.map +4 -4
  35. package/dist/plugin/index.d.ts.map +1 -1
  36. package/dist/plugin/index.js +1520 -187
  37. package/dist/plugin/index.js.map +4 -4
  38. package/dist/types.d.ts +12 -3
  39. package/dist/types.d.ts.map +1 -1
  40. package/package.json +7 -4
  41. package/dist/combinators/lazy.d.ts +0 -14
  42. package/dist/combinators/lazy.d.ts.map +0 -1
@@ -0,0 +1,63 @@
1
+ import type { Combinator, ParseContext, ParseError, ParseResult } from '../types.ts';
2
+ /**
3
+ * Run a compiled/interpreted grammar entry against an input and collect the raw
4
+ * outcome a tool needs to shape a parse result — WITHOUT the consumer having to
5
+ * hand-build a `ctx`, branch on function-vs-combinator, or scan for leftover
6
+ * input itself.
7
+ *
8
+ * A `compile()`/macro grammar hands you a map of bare parse FUNCTIONS; the
9
+ * interpreter hands you COMBINATORS. `run()` invokes either, threads the standard
10
+ * framework ctx (trivia log, recover/expect error sink, the `ctx.build` host,
11
+ * grammar state), and — given the grammar's trivia parser — reports where
12
+ * non-trivia input was left unconsumed. The consumer keeps only its own policy:
13
+ * how to shape the tree and how to turn diagnostics into its error type.
14
+ */
15
+ /** A compiled rule (macro/`compile()` output) OR an interpreter combinator. */
16
+ export type Runnable = ((input: string, pos: number, ctx: ParseContext) => ParseResult<unknown>) | Combinator<unknown>;
17
+ export type RunOptions = {
18
+ /** `ctx.build` host — makes structural `node()` rules build a CST / AST via the
19
+ * host instead of their own eval builders. Omit for a grammar's own builders. */
20
+ build?: ParseContext['build'];
21
+ /** Initial grammar state threaded into `ctx.state`. */
22
+ state?: unknown;
23
+ /**
24
+ * The grammar's trivia rule. A root rule consumes trivia BETWEEN terms but not
25
+ * after the last one, so trailing whitespace/comments would otherwise look like
26
+ * unparsed input. Given the trivia rule, `run` skips that tail before computing
27
+ * `unconsumedFrom` — so only real leftover is reported. Also encodes dialect
28
+ * differences for free: pass the CSS trivia and a trailing `//` counts as
29
+ * leftover; pass the Less trivia (which treats `//` as a line comment) and it
30
+ * doesn't. An UNTERMINATED comment (which the trivia rule won't match) surfaces
31
+ * at its start. Omit to require the parse to reach the exact end itself.
32
+ */
33
+ trivia?: Runnable;
34
+ };
35
+ export type RunResult = {
36
+ ok: boolean;
37
+ /** The entry's value on success; undefined on failure. */
38
+ value: unknown;
39
+ span: {
40
+ start: number;
41
+ end: number;
42
+ };
43
+ /** Expected-token set when the TOP-LEVEL parse failed (empty on success). */
44
+ expected: string[];
45
+ /** `recover()` / `expect()` diagnostics collected during the parse (in order). */
46
+ errors: ParseError[];
47
+ /**
48
+ * Flat trivia log for building a trivia map. Entry width depends on whether the
49
+ * grammar uses labeled trivia: 2 numbers per entry (`start, end`) for plain
50
+ * trivia, 3 numbers per entry (`start, end, kindIndex`) for labeled trivia
51
+ * (grammars with `label()` arms in their trivia choice). Use `buildTriviaIndex`
52
+ * / `triviaEntries` to consume it format-agnostically rather than iterating raw.
53
+ */
54
+ triviaLog: number[];
55
+ /** Offset where unparsed input begins — the first non-trivia character the parse
56
+ * left unconsumed (trailing trivia skipped when `trivia` is given), or null if
57
+ * the whole input was consumed. This is how you detect "the grammar stopped short,
58
+ * there's junk here". Only meaningful on success — a failed parse reports its own
59
+ * `span`/`expected`. */
60
+ unconsumedFrom: number | null;
61
+ };
62
+ export declare function run(entry: Runnable, input: string, options?: RunOptions): RunResult;
63
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/functional/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEpF;;;;;;;;;;;;GAYG;AAEH,+EAA+E;AAC/E,MAAM,MAAM,QAAQ,GAChB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAAK,WAAW,CAAC,OAAO,CAAC,CAAC,GACzE,UAAU,CAAC,OAAO,CAAC,CAAA;AAEvB,MAAM,MAAM,UAAU,GAAG;IACvB;qFACiF;IACjF,KAAK,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IAC7B,uDAAuD;IACvD,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,OAAO,CAAA;IACX,0DAA0D;IAC1D,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IACpC,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,kFAAkF;IAClF,MAAM,EAAE,UAAU,EAAE,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB;;;;4BAIwB;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B,CAAA;AAKD,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,SAAS,CAgCvF"}