A comprehensive expression editor built with ANTLR4, featuring real-time syntax highlighting, error detection, and multi-platform support. The project consists of a modern web editor and a powerful analyzer engine that supports WebAssembly and Python FFI.
- Real-time syntax highlighting with CodeMirror 6
- Error detection and display with inline diagnostics
- Intelligent autocompletion with context-aware suggestions
- Code formatting with proper indentation
- Hover tooltips for function documentation
- Dark/light theme support
- Smart bracket matching and folding
- ANTLR4-based parsing for mathematical and logical expressions
- WebAssembly support for browser integration
- Python FFI bindings for native integration
- Optimized WASM builds with TinyGo for minimal binary sizes
- Multiple compilation targets (native Go, WASM, Python FFI)
- Arithmetic operators:
+,-,*,/,^(with proper precedence) - Comparison operators:
<,<=,>,>=,==,!= - Logical operators:
&&,|| - Literals: integers, floats, strings, booleans
- Column references:
[column_name]format - Function calls:
FUNCTION_NAME(arg1, arg2, ...)format - Parentheses: for expression grouping
Start the development server:
cd editor-app
npm install
npm startNavigate to http://localhost:4200 to use the editor.
Build optimized WASM modules for browser usage:
# From project root
docker build --target wasm-output --output=type=local,dest=editor-app/public -f analyzer/Dockerfile .Install and use the Python bindings:
cd analyzer/ffi/python
pip install .Example usage:
from antlr_analyzer import Analyzer
analyzer = Analyzer()
result = analyzer.tokenize("age > 18 AND name = 'John'")
if result.is_valid:
for token in result.tokens:
print(f"{token.text} -> {token.token_type.name}")
else:
for error in result.errors:
print(f"Error: {error.message}")antlr-editor/
βββ grammar/ # ANTLR4 grammar definitions
β βββ Expression.g4 # Main expression grammar file
β βββ grammar.md # Grammar documentation
βββ analyzer/ # Go-based ANTLR4 analyzer engine
β βββ core/ # Core analyzer logic
β βββ wasm/ # WebAssembly target
β βββ ffi/ # Python FFI and C shared library
β βββ gen/ # Generated parser code (git-ignored)
β βββ codegen.sh # Parser generation script
β βββ Dockerfile # Multi-stage build for ANTLR generation
βββ editor-app/ # Angular-based web editor
β βββ src/app/antlr-editor/ # Main editor component
β β βββ extensions/ # CodeMirror extensions
β β βββ completion/ # Autocompletion
β β βββ format/ # Code formatting
β β βββ lint/ # Error linting
β β βββ syntax-highlight/ # Syntax highlighting
β β βββ tooltip/ # Hover tooltips
β βββ src/wasm/ # WASM integration
βββ .github/workflows/ # CI/CD pipelines
βββ .devcontainer/ # Development container configuration
- Node.js 18+ and npm
- Go 1.24.6+
- Docker (for ANTLR code generation)
- Angular CLI (
npm install -g @angular/cli)
-
Clone the repository:
git clone <repository-url> cd antlr-editor
-
Generate ANTLR parser code:
docker build --target antlr-generated --output=type=local,dest=analyzer/gen/parser -f analyzer/Dockerfile . -
Install editor dependencies:
cd editor-app npm install -
Build WASM module:
npm run build:wasm
cd editor-app
npm start # Start development server
npm run build # Build production bundle
npm run test # Run unit tests
npm run lint # Run linter
npm run format # Format codecd analyzer
./codegen.sh # Generate ANTLR parser
go test ./... # Run tests
go build ./... # Build all targets
golangci-lint run # Run linterTry these sample expressions in the editor:
// Arithmetic
2 + 3 * 4
(10 + 5) / 3
// Comparisons and logic
age >= 18 && status == 'active'
[price] * [quantity] > 100
// Functions
MAX(a, b, c)
ROUND([value], 2)
// Complex expressions
([salary] + [bonus]) * 0.8 > MIN_THRESHOLD && [department] == 'Engineering'- Analyzer Documentation - Detailed analyzer module guide
- Python FFI Documentation - Python bindings usage
- Grammar Definition - ANTLR4 grammar specification
- Development Guidelines - Contributing and development rules
The project includes GitHub Actions workflows for:
- Analyzer CI: Go testing, linting, and building
- Editor App CI: Angular testing, building, and deployment
- WASM Build: Automated WASM generation and optimization
- Python FFI: Testing and packaging Python bindings
This project is licensed under the MIT License - see the LICENSE file for details.