ANTLR-powered โข Type-safe โข Extensible โข Monorepo
Architecture โข Packages โข Development
A production-grade Abstract Syntax Tree (AST) parsing toolkit built with TypeScript and ANTLR v4. Currently supports JavaScript parsing with an architecture designed for multi-language extensibility.
The Problem:
Traditional AST tools:
- Tightly coupled to single languages โ
- Difficult to extend or customize โ
- Limited type safety โ
- Complex integration โ
The Solution:
AST Toolkit:
- Clean, extensible architecture โ
- ANTLR-powered parsing โ
- Full TypeScript type safety โ
- Monorepo structure for modularity โ
Result: Production-ready AST parsing with a foundation for supporting any programming language.
AST is a foundation package for the SylphxAI MCP family, not an MCP server. It
owns the @sylphlab/ast-* package line: ANTLR-backed parser contracts, typed
node interfaces, source spans, grammar fixtures, and JavaScript-first package
behavior.
Rust-native MCP products such as Architecture Reader MCP and CodeRAG may use AST outputs only through public package exports, generated fixtures, or stable contract files. They must not import workspace internals or add a TypeScript MCP adapter here.
See the family roadmap:
docs/roadmap/mcp-family-ast-foundation.md.
| Feature | Description | Benefit |
|---|---|---|
| ANTLR v4 | Industry-standard parser generator | Proven, battle-tested |
| Type-safe | Full TypeScript with strict mode | Catch errors at compile-time |
| Extensible | Core + language modules | Easy to add new languages |
| Visitor Pattern | ANTLR parse tree โ Custom AST | Clean transformation |
- Monorepo structure - Organized with Bun workspaces + Turborepo
- Modern tooling - Bun, Biome, Turborepo, and commitlint
- Testing - Vitest for fast, reliable tests
- Build -
tsupfor lightning-fast builds with type declarations - Versioning - Changesets for version management
@sylphlab/ast-core
- Generic AST node interfaces and types
- Foundation for all language parsers
- Zero dependencies
- Fully typed
@sylphlab/ast-javascript
- JavaScript/ECMAScript parser
- ANTLR-generated lexer and parser
- Custom visitor for AST transformation
- Depends on:
@sylphlab/ast-core,antlr4ts
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ @sylphlab/ast-javascript โ
โ (JavaScript-specific parser) โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโ
โ depends on
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ @sylphlab/ast-core โ
โ (Generic AST interfaces & types) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Component | Technology | Purpose |
|---|---|---|
| Language | TypeScript 5.8 | Type safety & modern JS |
| Parser | ANTLR v4 | Grammar-based parsing |
| Monorepo | Bun workspaces | Dependency management |
| Build | Turborepo | Task orchestration |
| Bundler | tsup | Fast ESM/CJS builds |
| Testing | Vitest | Unit testing |
| Linting | Biome | Code quality |
| Formatting | Biome | Code style |
| Git Hooks | commitlint | Commit message checks |
| Versioning | Changesets | Version management |
# Clone repository
git clone https://github.com/SylphxAI/ast.git
cd ast
# Install dependencies
bun install
# Build all packages
bun run build
# Run tests
bun run testimport { parse } from '@sylphlab/ast-javascript';
const code = `
const greeting = "Hello, World!";
console.log(greeting);
`;
const ast = parse(code);
console.log(ast);-
Separation of Concerns
- Core types separated from language implementations
- Each language parser in its own package
-
Extensibility
- Easy to add new language parsers
- Shared core interfaces for consistency
-
Type Safety
- Strict TypeScript throughout
- Full type inference
-
ANTLR Integration
- Grammar files (
.g4) define language syntax - Generated lexer/parser from grammar
- Custom visitor transforms parse tree to AST
- Grammar files (
Source Code (String)
โ
โผ
ANTLR Lexer
(Tokenization)
โ
โผ
ANTLR Parser
(Parse Tree)
โ
โผ
Custom Visitor
(Transformation)
โ
โผ
Custom AST
(@sylphlab/ast-core types)
ast/
โโโ packages/
โ โโโ core/ # @sylphlab/ast-core
โ โ โโโ src/
โ โ โโโ package.json
โ โ โโโ tsconfig.json
โ โโโ javascript/ # @sylphlab/ast-javascript
โ โโโ src/
โ โโโ grammar/ # .g4 grammar files
โ โโโ package.json
โ โโโ tsconfig.json
โโโ package.json # Root workspace config
โโโ turbo.json # Turborepo configuration
โโโ README.md
# Development
bun run test:watch # Watch mode for tests
# Building
bun run build # Build all packages
turbo run build # Build with Turborepo
# Testing
bun run test # Run all tests
bun run test:watch # Watch mode for tests
# Code Quality
bun run lint # Lint all packages
bun run lint:fix # Auto-fix linting issues
bun run format # Format code with Biome
bun run check-format # Check formatting
bun run typecheck # TypeScript type checking
# Full Validation
bun run validate # Format/lint, generated parser freshness, typecheck, test, build
# ANTLR (JavaScript package)
cd packages/javascript
bun run antlr # Regenerate committed parser files after grammar changes-
Create package directory
mkdir packages/new-language cd packages/new-language -
Create package.json
{ "name": "@sylphlab/ast-new-language", "version": "0.0.0", "dependencies": { "@sylphlab/ast-core": "workspace:*", "antlr4ts": "^0.5.0-alpha.4" } } -
Add grammar file
- Find or create ANTLR
.g4grammar for the language - Place in
grammar/directory
- Find or create ANTLR
-
Implement visitor
- Create custom visitor to transform ANTLR parse tree
- Map to
@sylphlab/ast-coretypes
-
Export parser
export function parse(code: string): AstNode { // Implementation }
- Monorepo structure with Bun + Turborepo
- Core AST type definitions (
@sylphlab/ast-core) - JavaScript parser package (
@sylphlab/ast-javascript) - ANTLR v4 integration
- ECMAScript grammar integration
- Basic visitor structure
- Build system configuration
- Testing infrastructure
- Code quality tooling (Biome, commitlint)
- Complete AST visitor implementation
- Comprehensive test coverage
- Position tracking improvements
- Grammar validation and refinement
- Support for additional JavaScript features
- TypeScript parser
- Python parser
- Go parser
- AST manipulation utilities
- Pretty printer (AST โ source code)
- Documentation site
# Run all tests
bun run test
# Watch mode
bun run test:watch
# Test specific package
cd packages/javascript
bun run testimport { describe, it, expect } from 'vitest';
import { parse } from '@sylphlab/ast-javascript';
describe('JavaScript Parser', () => {
it('should parse variable declarations', () => {
const code = 'const x = 42;';
const ast = parse(code);
expect(ast).toBeDefined();
});
});Strict mode enabled with:
noImplicitAny: truestrictNullChecks: truestrictFunctionTypes: true
Biome owns formatting and linting. The root biome.json is the source of truth for code style and lint behavior.
Grammar generation:
antlr4ts -visitor -listener -o src/generated grammar/*.g4- ESTree Specification (JavaScript AST spec)
- TypeScript Compiler API
Contributions are welcome! Please follow these guidelines:
- Open an issue - Discuss changes before implementing
- Fork the repository
- Create a feature branch -
git checkout -b feature/my-feature - Follow code standards - Run
bun run validate - Write tests - Maintain high coverage
- Commit with conventional commits -
feat:,fix:,docs:, etc. - Submit a pull request
feat(javascript): add support for async/await
fix(core): correct position tracking for nested nodes
docs(readme): update installation instructions
Repository metadata for tools and agents lives in project.manifest.json.
Package releases run through the shared Sylphx release workflow and are complete only after CI, the Release workflow, and npm registry readback for changed AST packages. Parser behavior changes additionally require package tests and consumer smoke evidence for affected parser contracts.
MIT ยฉ Sylphx
Built with:
- ANTLR - Parser generator
- antlr4ts - ANTLR runtime for TypeScript
- TypeScript - Language
- Bun - Package manager and test/runtime tooling
- Turborepo - Monorepo tool
- Vitest - Testing framework
Type-safe AST parsing for the modern web
Built with TypeScript and ANTLR
sylphx.com โข
@SylphxAI โข
hi@sylphx.com