@thi.ng/parse
Version:
Purely functional parser combinators & AST generation for generic inputs
37 lines • 1.1 kB
TypeScript
import type { Fn } from "@thi.ng/api";
import type { Parser, ScopeTransform } from "../api.js";
/**
* Side effect only. Higher order scope transform. Traverses current AST
* node and all children and prints each node's ID, result and reader
* state (if available). Also see {@link print}.
*
* @remarks
* The optional `fn` function is used to print each AST node (default:
* `console.log`).
*
* @param scope -
* @param ctx -
* @param level -
*/
export declare const xfPrint: (fn?: Fn<string, void>) => ScopeTransform<any>;
/**
* Syntax sugar for `xform(parser, xfPrint)`.
*
* @example
* ```ts tangle:../../export/print.ts
* import { ALPHA, defContext, lit, oneOrMore, print, seq } from "@thi.ng/parse";
*
* print(seq([lit("["), oneOrMore(ALPHA), lit("]")]))(defContext("[abc]"));
* // seq: undefined
* // lit: "["
* // repeat1: undefined
* // oneOf: "a"
* // oneOf: "b"
* // oneOf: "c"
* // lit: "]"
* ```
*
* @param parser -
*/
export declare const print: <T>(parser: Parser<T>, fn?: Fn<string, void>) => Parser<T>;
//# sourceMappingURL=print.d.ts.map