ANTLR4 IDE
A modern, web-based IDE for experimenting with ANTLR4 grammars. Write grammar files, test them against input text, and visualize parse trees in real-time.
Features
- ๐ Monaco Editor - Full-featured code editor with ANTLR4 syntax highlighting
- ๐ณ Interactive Parse Tree Visualization - D3-based tree rendering with zoom/pan controls
- ๐ Real-time Error Detection - Grammar validation and parsing errors displayed instantly
- ๐พ Project Management - Save and load entire projects as JSON files
- ๐ฆ Multiple Files - Support for multiple grammar files and input files
- ๐จ VS Code-inspired UI - Familiar IDE interface with resizable panels
- ๐ No Build Required - Works entirely in the browser using ANTLR4 JavaScript runtime
Quick Start
Prerequisites
- Node.js 18+
- npm or yarn
Installation
# Clone the repository
git clone <your-repo-url>
cd antlr4-ide
# Install dependencies
npm installDevelopment Setup
The application requires two servers running simultaneously:
- Backend Server (port 3001) - Handles file persistence, parsing, and AI features
- Frontend Server (port 3000) - Vite dev server for the React application
Option 1: Start both servers with a single command (recommended):
npm run dev:allOption 2: Start servers in separate terminals:
# Terminal 1: Start the backend server
npm run server
# or: npx tsx server/index.ts
# Terminal 2: Start the frontend dev server
npm run devThe application will be available at http://localhost:3000
Building for Production
npm run buildThe production build will be created in the dist/ directory.
Docker Deployment
Using Docker Compose (Recommended)
# Start the application
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the application
docker-compose downThe application will be available at:
- Frontend:
http://localhost:3000 - Backend API:
http://localhost:3001
Using Docker Directly
# Build the Docker image
docker build -t antlr4-ide .
# Run the container
docker run -d \
--name antlr4-ide \
-p 3000:3000 \
-p 3001:3001 \
-v antlr4ide_data:/app/data \
-e NODE_ENV=production \
-e PORT=3001 \
antlr4-ideData Persistence
User data is stored in a Docker volume:
# Backup data
docker cp antlr4-ide:/app/data ./backup
# Restore data
docker cp ./backup/. antlr4-ide:/app/data
# Reset to clean state (removes all user data)
docker-compose down -v && docker-compose up -dEnvironment Variables
Core Configuration
| Variable | Default | Description |
|---|---|---|
NODE_ENV |
development |
Node environment (development or production) |
PORT |
3001 |
Backend API port |
DATA_DIR |
./data |
Data storage directory for files and workspace |
AI Assistant Configuration
The AI assistant feature requires an API key from one of the supported providers:
| Variable | Default | Description |
|---|---|---|
AI_PROVIDER |
anthropic |
AI provider: anthropic, openai, or gemini |
AI_MODEL |
(per provider) | Model ID (optional, uses sensible defaults) |
AI_MAX_TOKENS |
2048 |
Maximum response tokens |
AI_TEMPERATURE |
0.7 |
Generation temperature |
ANTHROPIC_API_KEY |
- | API key for Anthropic (required if AI_PROVIDER=anthropic) |
OPENAI_API_KEY |
- | API key for OpenAI (required if AI_PROVIDER=openai) |
GEMINI_API_KEY |
- | API key for Google Gemini (required if AI_PROVIDER=gemini) |
Default models per provider:
- Anthropic:
claude-sonnet-4-20250514 - OpenAI:
gpt-4o - Gemini:
gemini-1.5-pro
Local Development Setup
Create a .env.local file in the project root:
# AI Provider Configuration
AI_PROVIDER=anthropic
AI_MODEL=claude-sonnet-4-20250514
# API Key (set only the one for your provider)
ANTHROPIC_API_KEY=your_key_here
# OPENAI_API_KEY=your_key_here
# GEMINI_API_KEY=your_key_hereDocker Compose Setup
For Docker, you can either:
-
Use environment variables (recommended for CI/CD):
ANTHROPIC_API_KEY=your_key docker-compose up -d
-
Create a
.envfile in the project root:ANTHROPIC_API_KEY=your_key_here
-
Edit
docker-compose.ymldirectly (not recommended for secrets)
Usage
Creating a Grammar
- Click the Grammar icon (โ๏ธ) in the sidebar to create a new grammar file
- Write your ANTLR4 grammar using standard syntax:
grammar Expr;
expr: term (('+'|'-') term)* ;
term: factor (('*'|'/') factor)* ;
factor: NUMBER | '(' expr ')' ;
NUMBER: [0-9]+ ;
WS: [ \t\r\n]+ -> skip ;Adding Input Text
- Click the Text icon (๐) in the sidebar to create a new input file
- Enter text to parse:
(10 + 20) * 3
Running the Parser
- Set the Start Rule in the header (e.g.,
expr) - Click the Run button
- View the results:
- Console tab: Errors and warnings
- Tokens tab: Lexer token stream
- Parse Tree panel: Visual representation of the parse tree
Managing Files
- Rename: Double-click a file or click the edit icon
- Delete: Click the trash icon (requires at least 1 file to remain)
- Save Project: Click the Save button to download as JSON
- Load Project: Click the Open button to load a saved project
Project Structure
src/
โโโ components/ # React components
โ โโโ CodeEditor.tsx # Monaco editor wrapper
โ โโโ TreeVisualizer.tsx # D3 parse tree visualization
โโโ types/ # TypeScript type definitions
โโโ utils/
โ โโโ antlr/ # ANTLR4 runtime implementation
โ โโโ index.ts # Main parsing orchestration
โ โโโ GrammarLoader.ts # Grammar file parser
โ โโโ Validation.ts # Grammar validation
โ โโโ LexerAdaptor.ts # Runtime lexer
โ โโโ ParserAdaptor.ts # Runtime parser
โ โโโ types.ts # ANTLR4-specific types
โโโ App.tsx # Main application component
โโโ main.tsx # Application entry point
Technology Stack
- React 19 - UI framework
- TypeScript 5.8 - Type safety
- Vite 6 - Build tool and dev server
- Monaco Editor - Code editor (same as VS Code)
- D3.js 7 - Parse tree visualization
- ANTLR4 4.13.2 - Parser runtime
- Lucide React - Icon library
- Tailwind CSS - Styling
Development
Available Scripts
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production buildnpm run type-check- Run TypeScript type checkingnpm run lint- Run ESLint
Type Checking
The project uses strict TypeScript configuration. Run type checking with:
npm run type-checkCode Style
ESLint is configured for code quality. Run linting with:
npm run lintConfiguration
Vite Configuration
The Vite configuration (vite.config.ts) includes:
- React plugin for JSX support
- Path alias
@/pointing tosrc/ - Development server on port 3000 (configurable)
TypeScript Configuration
The TypeScript configuration (tsconfig.json) uses:
- Strict type checking enabled
- Path mapping for
@/*imports - ES2022 target with DOM libraries
Grammar Validation
The application validates ANTLR4 grammars for:
- Undefined rule references - Parser rules referencing non-existent rules
- Undefined token references - References to tokens not defined in lexer
- Direct left-recursion - Simple cases of left-recursive rules
Parse Tree Visualization
The parse tree visualizer features:
- Horizontal layout - Left-to-right tree structure
- Color coding:
- ๐ข Green nodes: Parser rules
- ๐ต Blue nodes: Tokens
- ๐ด Red nodes: Errors
- Interactive controls:
- Click nodes to select tokens
- Zoom in/out with + and - buttons
- Reset view with refresh button
- Pan by dragging the canvas
Known Limitations
- Complex left-recursion detection is basic
- Fragment expansion limited to 10 levels
- Large grammars may impact performance
- Browser-based only (no command-line usage)
Troubleshooting
Build Errors
If you encounter build errors:
- Clear node_modules:
rm -rf node_modules package-lock.json - Reinstall:
npm install - Rebuild:
npm run build
Type Errors
If TypeScript errors persist:
- Run type check:
npm run type-check - Check import paths use
@/alias - Verify all files are in
src/directory
Runtime Errors
If the parser fails:
- Check grammar syntax in the console
- Verify start rule name is correct
- Ensure at least one grammar and input file exist
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and type checking
- Submit a pull request
License
This project is licensed under the MIT License.
Acknowledgments
- Built with ANTLR4 by Terence Parr
- Editor powered by Monaco Editor
- Visualization using D3.js
- UI inspired by VS Code
Support
For issues and questions:
- Create an issue on GitHub
- Check the ANTLR4 documentation
- Review example grammars
