---
title: Railroad
description: A grammar drawn as railroad tracks, from EBNF, PEG or combinator rules.
source: https://github.com/crabtalk/bezel/blob/main/crates/mermaid/src/diagrams/railroad/mod.rs
---

> One page of the bezel documentation. The index is https://bezel.gallery/llms.txt

# Railroad

```mermaid
railroad-ebnf-beta
title "Arithmetic Expression Grammar"

expression = term ( ( "+" | "-" ) term )* ;
term = factor ( ( "*" | "/" ) factor )* ;
factor = number | "(" expression ")" ;
number = digit+ ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
```

## Syntax

- `railroad-ebnf-beta` reads EBNF: `rule = … ;` with `|` for choice, `( )` to group, and `*`, `+` and `?` to repeat.
- `railroad-peg-beta` reads PEG: `rule <- … ;` with `/` for choice.
- `railroad-beta` reads combinators: `sequence(…)`, `choice(…)`, `zeroOrMore(…)`, `oneOrMore(…)`, `terminal("…")` and `nonterminal("…")`.
- `title` names the diagram; each rule is a track.
