Skip to content

goncalompontes/rail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rail

CI License Rust

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.


For Model Railroaders

Quick Start

// 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.exrail

Upload hello.exrail to your DCC-EX CommandStation.

Features

  • 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

Installation

cargo install railc

Requires Rust nightly. See CONTRIBUTING.md for build instructions.


For Compiler Enthusiasts

Architecture

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
└──────────────┘

Repository Structure

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

Build from Source

git clone https://github.com/pontes/rail
cd rail
cargo build --release

Run Tests

cargo test --workspace

All tests must pass. The project maintains 252+ tests with strict clippy linting.

Project Status

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.

Contributing

See CONTRIBUTING.md for guidelines.


License

This project is dual-licensed under MIT and Apache 2.0.

About

Rail DSL compiler — a domain-specific language for model railroad automation targeting DCC-EX CommandStation

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors