import type { Fn } from "@thi.ng/api" ; import type { Parser , ScopeTransform } from "../api.js" ; import { xform } from "../combinators/xform.js" ; import { indent } from "../utils.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  print .
 *
 *  remarks param scope param ctx param level export const xfPrint = ( fn = console . log ) => { const $print = ( scope , _ , level = 0 ) => { if ( ! scope ) return ; const prefix = indent ( level ) ; const state = scope . state ; const info = state ? ` (${ state . l }:${ state . c })` : "" ; fn ( `${ prefix }${ scope . id }${ info }: ${ JSON . stringify ( scope . result ) }` ) ; if ( scope . children ) { for ( let c of scope . children ) { $print ( c , _ , level + 1 ) ; } } return scope ; } ; return $print ; } ; example param parser export const print = < T > ( parser , fn ? ) => xform ( parser , xfPrint ( fn ) ) ;