Rail is a domain-specific language for model railroad automation. It compiles to EXRAIL, the scripting language for DCC-EX CommandStation controllers.
Rail lets you describe layout behavior — turnouts, signals, sensors, and automation logic — in a high-level syntax that compiles directly to the EXRAIL commands your CommandStation executes.
// hello.rail — blink a signal's headlight
startup {
pin PB7 = output
loop {
on PB7
delay 1000
off PB7
delay 1000
}
}Compile with:
railc hello.rail -o hello.exrailUpload hello.exrail to your DCC-EX CommandStation.
- Declarative syntax — describe what you want, not how
- Safe by default — compile-time checks catch wiring errors before they reach your layout
- DCC-EX native — compiles directly to EXRAIL, no runtime needed
- Procedural automation — define reusable behaviors with parameters
- Composite types — model turnouts, signals, and sensors as structured objects
cargo install railcRequires Rust nightly. See CONTRIBUTING.md for build instructions.
The Rail compiler transforms source text through several intermediate representations:
Source (.rail)
│
▼
┌──────────────┐
│ Lexer │ logos-based tokenizer
├──────────────┤
│ Parser │ chumsky combinator parser → AST
├──────────────┤
│ Resolver │ two-phase name resolution → typed DefIds
├──────────────┤
│ Type Checker │ type inference → HIR (High-level IR)
├──────────────┤
│ MIR │ CFG-based Mid-level IR
├──────────────┤
│ Optimizer │ constant folding, DCE, propagation
├──────────────┤
│ Codegen │ (planned) → EXRAIL output
└──────────────┘
rail/
├── Cargo.toml # Workspace root
├── rail-core/ # Compiler library
│ ├── src/
│ │ ├── lexer.rs # Tokenizer
│ │ ├── parser/ # Parser combinators (11 files)
│ │ ├── semantic/ # Resolution, type checking, HIR
│ │ └── optimizer/ # MIR types, lowering, passes
│ └── Cargo.toml
├── railc/ # CLI binary (placeholder)
│ └── src/
└── docs/ # Language documentation
git clone https://github.com/pontes/rail
cd rail
cargo build --releasecargo test --workspaceAll tests must pass. The project maintains 252+ tests with strict clippy linting.
Rail is currently in active development as a CS bachelor's thesis project. The compiler pipeline (lex → parse → resolve → type-check → HIR → MIR → optimize) is complete. EXRAIL codegen is the next major phase.
See CONTRIBUTING.md for guidelines.
This project is dual-licensed under MIT and Apache 2.0.