parseman 0.2.0 → 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 (54) hide show
  1. package/README.md +167 -126
  2. package/dist/combinators/choice.d.ts.map +1 -1
  3. package/dist/combinators/completions.d.ts +17 -0
  4. package/dist/combinators/completions.d.ts.map +1 -0
  5. package/dist/combinators/grammar.d.ts +20 -4
  6. package/dist/combinators/grammar.d.ts.map +1 -1
  7. package/dist/combinators/guard.d.ts +2 -2
  8. package/dist/combinators/guard.d.ts.map +1 -1
  9. package/dist/combinators/keywords.d.ts +22 -0
  10. package/dist/combinators/keywords.d.ts.map +1 -0
  11. package/dist/combinators/literal.d.ts.map +1 -1
  12. package/dist/combinators/node.d.ts +24 -0
  13. package/dist/combinators/node.d.ts.map +1 -0
  14. package/dist/combinators/parser.d.ts +7 -7
  15. package/dist/combinators/parser.d.ts.map +1 -1
  16. package/dist/combinators/probe.d.ts +13 -0
  17. package/dist/combinators/probe.d.ts.map +1 -0
  18. package/dist/combinators/recover.d.ts.map +1 -1
  19. package/dist/combinators/regex.d.ts.map +1 -1
  20. package/dist/combinators/repeat.d.ts.map +1 -1
  21. package/dist/combinators/scanTo.d.ts.map +1 -1
  22. package/dist/combinators/sequence.d.ts.map +1 -1
  23. package/dist/combinators/trivia-skip.d.ts +33 -0
  24. package/dist/combinators/trivia-skip.d.ts.map +1 -0
  25. package/dist/combinators/withCtx.d.ts +1 -1
  26. package/dist/compiler/codegen.d.ts +13 -4
  27. package/dist/compiler/codegen.d.ts.map +1 -1
  28. package/dist/cst/grammar.d.ts +33 -2
  29. package/dist/cst/grammar.d.ts.map +1 -1
  30. package/dist/cst/incremental.d.ts +4 -2
  31. package/dist/cst/incremental.d.ts.map +1 -1
  32. package/dist/cst/trivia-index.d.ts +50 -0
  33. package/dist/cst/trivia-index.d.ts.map +1 -0
  34. package/dist/cst/types.d.ts +7 -7
  35. package/dist/cst/types.d.ts.map +1 -1
  36. package/dist/functional/doc.d.ts +53 -0
  37. package/dist/functional/doc.d.ts.map +1 -0
  38. package/dist/index.cjs +953 -221
  39. package/dist/index.cjs.map +4 -4
  40. package/dist/index.d.ts +12 -2
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +6519 -226
  43. package/dist/index.js.map +4 -4
  44. package/dist/plugin/evaluator.d.ts +26 -6
  45. package/dist/plugin/evaluator.d.ts.map +1 -1
  46. package/dist/plugin/index.cjs +1164 -215
  47. package/dist/plugin/index.cjs.map +4 -4
  48. package/dist/plugin/index.d.ts +5 -2
  49. package/dist/plugin/index.d.ts.map +1 -1
  50. package/dist/plugin/index.js +1164 -215
  51. package/dist/plugin/index.js.map +4 -4
  52. package/dist/types.d.ts +51 -6
  53. package/dist/types.d.ts.map +1 -1
  54. package/package.json +1 -1
@@ -2,14 +2,34 @@
2
2
  * Statically evaluates parseman combinator call expressions from an oxc AST
3
3
  * into actual Combinator<unknown> objects by calling the real library functions.
4
4
  *
5
- * Returns null for anything unresolvable (user closures, external variables,
6
- * template literals, computed keys, etc.) — callers leave those as-is.
5
+ * Returns null for anything unresolvable (external variables, template literals,
6
+ * computed keys, etc.) — callers leave those as-is.
7
7
  */
8
8
  import type { Expression, Node } from '@oxc-project/types';
9
9
  import type { Combinator } from '../types.ts';
10
- export type Scope = Map<string, Combinator<unknown>>;
11
- /** Try to evaluate an oxc AST Expression as a parseman Combinator. Returns null if impossible. */
12
- export declare function evaluateExpr(node: Expression, scope: Scope): Combinator<unknown> | null;
13
- /** Check if an AST node references any name from the given set (used to detect parseman usage). */
10
+ export type ScopeEntry = {
11
+ combi: Combinator<unknown>;
12
+ mfSrcs: string[];
13
+ };
14
+ export type Scope = Map<string, ScopeEntry>;
15
+ /** Evaluate a single combinator expression. Returns null if unresolvable. */
16
+ export declare function evaluateExpr(node: Expression, scope: Scope, code?: string, mapFnSources?: string[]): Combinator<unknown> | null;
17
+ /**
18
+ * Evaluate a `parser(g => { ... return { ruleName: combinator, ... } })` call.
19
+ * Returns a map of rule names → defined Combinators, or null if the factory
20
+ * can't be statically evaluated.
21
+ *
22
+ * mapFnSources is populated with the sources for mapFns that codegen will push
23
+ * when compiling each returned rule — each rule's entry in the map will produce
24
+ * a sub-slice of mapFnSources aligned to its specific ctx.mapFns.
25
+ *
26
+ * Important: this function uses a SEPARATE accumulator for body statement
27
+ * evaluation so that only the return-expression phase adds entries to the
28
+ * caller-provided mapFnSources (which is what compile() will receive).
29
+ * The body-phase entries are stored as `mfSrcs` on localScope entries and
30
+ * replayed when those entries are referenced during return evaluation.
31
+ */
32
+ export declare function evaluateParserFactory(factoryNode: Expression, scope: Scope, code: string, mapFnSources: string[]): Map<string, Combinator<unknown>> | null;
33
+ /** Check if an AST node references any name from the given scope or names set. */
14
34
  export declare function referencesAny(node: Node, names: Set<string>, scope: Scope): boolean;
15
35
  //# sourceMappingURL=evaluator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;AAcpD,kGAAkG;AAClG,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAsBvF;AAoCD,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAcnF"}
1
+ {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"m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