A compact TypeScript parser framework and educational playground for tokenization, parsing, lookahead analysis, and AST construction. The codebase is organized so you can experiment with parser components and run small demos to validate behavior.
Highlights
- Small, modular parser components (tokenizer, reducer, parser)
- Lookahead analysis utilities to inspect upcoming tokens
- AST types, converters and traversal helpers
- Visualizer that converts, with different granularity, the instruction or basic blocks to valid mermaid code
- Focused demos under
demos/for quick exploration
Requirements
- Deno (recommended for running the demos as provided)
Run a demo with Deno (examples):
deno run demos/struct.ts
deno run demos/if_basic_blocks.ts
deno run demos/grammar.tsmain.ts— simple entry point for quick experimentsdemos/— runnable examples demonstrating parser usagesrc/— core TypeScript modules (AST, traversal, utilities)src/ast— AST node definitions, converters, and helpersparser/— tokenizer, parser, reducer, and lookahead analyzerexceptions/— custom parser exception classes
- Use the demos to verify parser behavior after changes.
- The code is written to run with Deno-style imports; to run under Node.js,
adjust imports and toolchain (e.g., compile with
tscor usets-node).
- Modify source files under
src/andparser/and exercise changes via the demos. Keep the demos minimal and self-contained so they clearly demonstrate the intended parsing behavior.
Contributions and bug reports are welcome. Please open an issue with a short description and a minimal reproduction, or submit a pull request with focused changes and updated demos where applicable.