UNPKG

solidity-antlr4

Version:

Solidity Lang Lexer and Parser by official ANTLR4 grammar

21 lines (20 loc) 456 B
import { traverse } from "./traverse.js"; export const visit = (ast, handlers) => { traverse(ast, (p) => { const nodeType = p.node.type; handlers.enter?.(p); handlers[nodeType]?.(p); handlers[`exit${nodeType}`]?.(p); handlers.exit?.(p); }); }; export const visitNodes = (ast, callback) => { const nodes = []; visit(ast, { enter(path) { if (callback(path)) nodes.push(path.node); } }); return nodes; };