/** * Grammar-aware CST traversal. `createVisitor(grammar, handlers)` consumes the * reflection stamped on interpreted `rules()` maps and macro/compiled grammar * maps, precomputes tag dispatch once, and returns a reusable `visit(root)` fn. */ import type { CSTChild, CSTNode } from './types.ts'; import { type GrammarWithReflection } from './reflection.ts'; export type Walkable = { readonly _tag: string; readonly type?: string; readonly children?: ReadonlyArray; }; type GrammarNodeType = G extends GrammarWithReflection ? NodeType : G extends Record ? Extract : string; type GrammarNodeTag = G extends GrammarWithReflection ? NodeTag : never; type NodeForType = Extract extends never ? CSTNode & { readonly type: Type; } : Extract & { readonly type: Type; }; export type VisitorHandler = (node: N, parent: Root | null, ctx: C) => void; export type VisitorSpec = { enter?(node: N, parent: N | null, ctx: C): boolean | void; leave?(node: N, parent: N | null, ctx: C): void; type?: { [K in GrammarNodeType]?: VisitorHandler, N, C>; }; tag?: { [K in GrammarNodeTag]?: VisitorHandler>, N, C>; }; }; export declare function createVisitor(grammar: G, spec: VisitorSpec): (root: N, ctx?: C) => void; export {}; //# sourceMappingURL=walk.d.ts.map