/** * Statically evaluates parseman combinator call expressions from an oxc AST * into actual Combinator objects by calling the real library functions. * * Returns null for anything unresolvable (external variables, template literals, * computed keys, etc.) — callers leave those as-is. */ import type { Expression, Node } from '@oxc-project/types'; import type { Combinator } from '../types.ts'; import { type RulesOptions } from '../combinators/parser.ts'; import type { ReducerResolver } from './reducer-resolver.ts'; /** Install (or clear, with `null`) the resolver for the module being transformed. */ export declare function setReducerResolver(r: ReducerResolver | null, entrySource?: string | null): void; /** * Map a free lexical name read by a direct node builder to the import it came from * in the AUTHORING module. A name that resolves is no longer a refusal — the node * carries `{ source, imported }` provenance, and a downstream `compose()` re-binds * it by re-emitting the same import into the consuming module. A name that does not * resolve (a module-private const, a genuinely undefined read) stays a refusal. */ export type BuilderImportResolver = (name: string) => { source: string; imported: string; } | null; /** Install (or clear, with `null`) the import-provenance resolver for the module being transformed. */ export declare function setBuilderImportResolver(r: BuilderImportResolver | null): void; export type ScopeEntry = { combi: Combinator; mfSrcs: string[]; }; export type Scope = Map; type WordFactoryEntry = { tag: 'wordFactory'; boundary: string; caseInsensitive: boolean; }; type WhenFactoryEntry = { tag: 'whenFactory'; caseInsensitive: boolean; }; /** THE reader for an object-literal property key, for every consumer in the plugin. * * Returns the key a JavaScript engine would use, or null when the property does not * name a static key at all — a spread, a rest, or a COMPUTED key whose value is not * known until runtime. * * Both halves are load-bearing and each was got wrong somewhere: * - a quoted key is a `Literal`, not an `Identifier`. Reading only `key.name` sees * `{ 'hostMode': 'cst' }` as having no hostMode, and drops the option SILENTLY. * - `key.name` is also populated for a COMPUTED key `{ [hostMode]: … }`, where the * identifier is a variable and the actual key is its value. Reading only * `key.name` there invents an option the source never set. * * So an Identifier-only reader both misses keys that are present and matches keys that * are not. Three option readers in plugin/index.ts each re-derived one wrong half; the * fix is this one function, imported. */ export declare function propName(p: { type?: string; computed?: boolean; key?: unknown; }): string | null; /** Evaluate makeWord(boundary?, opts?) to a factory entry (not a combinator). */ export declare function evaluateWordFactory(node: Expression, scope: Scope, code?: string): WordFactoryEntry | null; /** Evaluate makeWhen(opts?) to a dispatch-arm factory entry (not a combinator). */ export declare function evaluateWhenFactory(node: Expression, scope: Scope, code?: string): WhenFactoryEntry | null; /** Evaluate a single combinator expression. Returns null if unresolvable. */ export declare function evaluateExpr(node: Expression, scope: Scope, code?: string, mapFnSources?: string[]): Combinator | null; /** * Evaluate a `const X = [combinator, …]` array literal into an array of * Combinators. Lets a shared option array (e.g. a `skip` set reused across * `scanTo`/`balanced` calls) be referenced by name — `{ skip: X }` — instead of * inlining the array at every call site. Returns null when `node` isn't an array * literal of statically-resolvable combinators. */ export declare function evaluateCombinatorArray(node: Expression, scope: Scope, code?: string): Combinator[] | null; export declare function evaluateStaticValue(node: Expression, scope: Scope, code?: string): unknown; /** * Evaluate a `parser(g => { ... return { ruleName: combinator, ... } })` call. * Returns a map of rule names → defined Combinators, or null if the factory * can't be statically evaluated. * * mapFnSources is populated with the sources for mapFns that codegen will push * when compiling each returned rule — each rule's entry in the map will produce * a sub-slice of mapFnSources aligned to its specific ctx.mapFns. * * Important: this function uses a SEPARATE accumulator for body statement * evaluation so that only the return-expression phase adds entries to the * caller-provided mapFnSources (which is what compile() will receive). * The body-phase entries are stored as `mfSrcs` on localScope entries and * replayed when those entries are referenced during return evaluation. */ export declare function evaluateParserFactory(factoryNode: Expression, scope: Scope, code: string, mapFnSources: string[], // receives ONLY the return-expression mfSrcs out?: { reason?: string; }, // receives a SPECIFIC failure reason (see evalBodyStatements) /** * The `rules({ … }, factory)` options this call site declared, THREADED THROUGH * rather than reapplied afterwards. * * `plugin/index.ts` used to stamp `grammarScanSkip`, `grammarHostMode` and * `grammarTrackLines` onto the evaluated rules in three loops of its own, * carrying a comment that it had to "because the macro evaluates the FACTORY * directly and never calls `rules()`". It calls `rules()` now, so the options * belong where every other caller puts them: in the argument. That also gets * the `trackLines` half right for the first time — `rules()` does not merely * stamp it, it WRAPS each rule in a `grammarParser({ trackLines: true })` scope * (`parser.ts:228-242`), which the macro's stamp-only copy never did. */ options?: RulesOptions): Map> | null; /** A combinator slot created by ref() — has a callable `define`. */ type DefinableRef = Combinator & { define(p: Combinator): void; }; /** * If `init` is a bare `ref()` call, evaluate it to a real ref placeholder and * register it in scope under `name`. Returns the ref, or null if `init` isn't * a `ref()` call. Used by the macro pre-pass so standalone refs resolve before * compilation (parity with the interpreter / compile()). */ export declare function evaluateRefDeclaration(init: Expression, name: string, scope: Scope): DefinableRef | null; /** * Apply a `someRef.define(expr)` statement: resolve the target ref from scope, * evaluate the argument to a combinator, and call `.define()`. Returns true on * success. The macro removes the original statement from the output (it would * otherwise reference the stripped import); returning false signals "leave it". */ export declare function applyDefineStatement(callExpr: Expression, scope: Scope, code: string): boolean; /** Check if an AST node references any name from the given scope or names set. */ export declare function referencesAny(node: Node, names: Set, scope: Scope): boolean; export {}; //# sourceMappingURL=evaluator.d.ts.map