merIDK / Diagram types / Railroad (syntax) diagram
Mermaid railroad (syntax) diagram: example and syntax
Railroad diagrams draw a grammar as tracks you can follow, the way JSON and SQL are documented. Mermaid builds them from EBNF, ABNF or PEG grammars.
Open this example in the editor
Example code
railroad-ebnf-beta
title "Number"
number = [ "-" ] , digit , { digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
Result
railroad-ebnf-beta
title "Number"
number = [ "-" ] , digit , { digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;Syntax quick reference
- Rule:
name = ... ;. |is a choice,[ ]is optional,{ }repeats.- Other grammars:
railroad-abnf-betaandrailroad-peg-beta.
How to use it
- Open the example in the editor, or paste your own Mermaid code.
- Edit the code on the left. The preview updates as you type, and errors point to the line.
- Export SVG or PNG, copy a Markdown block for GitHub or Notion, or copy a share link.