UNPKG

bramble-parser

Version:

Bramble is a lightweight recursive descent parser that processes .havenfs files, returning a structured Json tree that can be used to construct an in-memory FS representation. The parser is based on line-based grammar, chunk headers, and metadata declarat

51 lines (41 loc) 1.32 kB
import { Glob } from "bun"; import { errorManager } from "./src/errors/errorManager"; import { BrambleLexer } from "./src/lexer"; import { BrambleFSParser } from "./src/parser/parser"; async function main() { try { const glob = new Glob("*.havenfs"); const paths = await Array.fromAsync(glob.scan(".")) if (paths.length === 0) { console.log("No .havenfs files found in the current directory."); return; } await Promise.all( paths.map(async (filePath) => { console.log("Found file:", filePath); const lexer = new BrambleLexer({document: filePath}); lexer.run(); // lexer.debugReadTokensByLine(); lexer.debugBranch(); // lexer.debugChunks(); const chunkMap = lexer.getChunkMap(); const parser = new BrambleFSParser(chunkMap); parser.run(); // parser.debugLibraries(); // parser.debugTagmap(); parser.debugFS(); const errors = errorManager.getAll(); if (errors.length > 0) { console.log("Errors found:", errors.length); errorManager.log(); } else { console.log("No errors found in", filePath); } errorManager.clear(); }) ); } catch (e) { console.error("Unexpected error:", e); } } main();