UNPKG

@ton-community/tlb-parser

Version:

Parse TLB syntax into TypeScript objects

46 lines (45 loc) 1.54 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const util_1 = __importDefault(require("util")); const index_1 = require("./index"); if (process.argv[2] === '--help' || process.argv[2] === '-h' || process.argv[2] === 'help') { help(); process.exit(0); } const inputPath = process.argv[2]; if (!inputPath) { console.error('No input file'); help(); process.exit(1); } if (!fs_1.default.existsSync(inputPath)) { console.error('Input file does not exist'); process.exit(1); } const input = fs_1.default.readFileSync(inputPath, 'utf-8'); class TestVisitor extends index_1.NodeVisitor { constructor() { super(); this.visited = {}; } genericVisit(node) { var _a; const key = node.constructor.name; this.visited[key] = ((_a = this.visited[key]) !== null && _a !== void 0 ? _a : 0) + 1; return super.genericVisit(node); } } const tree = (0, index_1.ast)(input); const visitor = new TestVisitor(); visitor.visit(tree); console.log(util_1.default.inspect(visitor.visited, { showHidden: false, depth: null, colors: true })); console.log(util_1.default.inspect(tree, { showHidden: false, depth: null, colors: true })); function help() { console.log('Usage: tlb-parser <input>'); console.log(' input: input file'); }