Railroad diagrams

Every diagram node, shown in the auto theme. Choose a theme to compare the same examples.

Sequence

1 2 3
Text version
        ╭───╮     ╭───╮     ╭───╮       
├┼──────│ 1 │─────│ 2 │─────│ 3 │─────┼┤
        ╰───╯     ╰───╯     ╰───╯       

Stack

1 2 3
Text version
        ╭───╮        
├┼──────│ 1 │──┐     
        ╰───╯  │     
     ┌─────────┘     
     │  ╭───╮        
     └──│ 2 │──┐     
        ╰───╯  │     
     ┌─────────┘     
     │  ╭───╮        
     └──│ 3 │──────┼┤
        ╰───╯        

Choice

1 2 3
Text version
       ╭───╮       
    ╭──│ 1 │──╮    
    │  ╰───╯  │    
    │         │    
    │  ╭───╮  │    
├┼──┼──│ 2 │──┼──┼┤
    │  ╰───╯  │    
    │         │    
    │  ╭───╮  │    
    ╰──│ 3 │──╯    
       ╰───╯       

Optional

foo bar
Text version
    ╭───────────╮                  
    │           │                  
    │  ╭─────╮  │                  
├┼──╯──│ foo │──╰─╮───────────╭──┼┤
       ╰─────╯    │           │    
                  │  ╭─────╮  │    
                  ╰──│ bar │──╯    
                     ╰─────╯       

OneOrMore

foo bar
Text version
        ╭─────╮        
├┼───╭──│ foo │──╮───┼┤
     │  ╰─────╯  │     
     │  ╭─────╮  │     
     ╰──│ bar │──╯     
        ╰─────╯        

ZeroOrMore

foo bar
Text version
    ╭───────────────╮    
    │               │    
    │    ╭─────╮    │    
├┼──╯─╭──│ foo │──╮─╰──┼┤
      │  ╰─────╯  │      
      ╰─bar───────╯      

Group

foo option 1 or two bar
Text version
                  ╭┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄╮                  
      ╭─────╮     ┆    ┌──────────┐    ┆     ╭─────╮      
├┼────│ foo │─────┼─╮──│ option 1 │──╭─┼─────│ bar │────┼┤
      ╰─────╯     ┆ │  └──────────┘  │ ┆     ╰─────╯      
                  ┆ │                │ ┆                  
                  ┆ │   ┌────────┐   │ ┆                  
                  ┆ ╰───│ or two │───╯ ┆                  
                  ┆     └────────┘     ┆                  
                  ╰┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄╯                  

HorizontalChoice

1 0 2 3 4 6 5 7 8 9 b a c d e
Text version
    ╭──────────────╮──────────────╮                  
    │    ╭───╮     │    ╭───╮     │    ╭───╮         
    │ ╭──│ 0 │──╮  │ ╭──│ 5 │──╮  │ ╭──│ a │──╮      
    │ │  ╰───╯  │  │ │  ╰───╯  │  │ │  ╰───╯  │      
    │ │         │  │ │         │  │ │         │      
    │ │  ╭───╮  │  │ │  ╭───╮  │  │ │  ╭───╮  │      
    │ ╭──│ 1 │──╮  │ ╭──│ 6 │──╮  │ ╭──│ b │──╮      
    │ │  ╰───╯  │  │ │  ╰───╯  │  │ │  ╰───╯  │      
    │ │         │  │ │         │  │ │         │      
    │ │  ╭───╮  │  │ │  ╭───╮  │  │ │  ╭───╮  │      
├┼──╯─┼──│ 2 │──┼─╮╰─┼──│ 7 │──┼─╮╰─┼──│ c │──┼─╭──┼┤
      │  ╰───╯  │ │  │  ╰───╯  │ │  │  ╰───╯  │ │    
      │         │ │  │         │ │  │         │ │    
      │  ╭───╮  │ │  │  ╭───╮  │ │  │  ╭───╮  │ │    
      ╰──│ 3 │──╯ │  ╰──│ 8 │──╯ │  ╰──│ d │──╯ │    
      │  ╰───╯  │ │  │  ╰───╯  │ │  │  ╰───╯  │ │    
      │         │ │  │         │ │  │         │ │    
      │  ╭───╮  │ │  │  ╭───╮  │ │  │  ╭───╮  │ │    
      ╰──│ 4 │──╯ │  ╰──│ 9 │──╯ │  ╰──│ e │──╯ │    
         ╰───╯    │     ╰───╯    │     ╰───╯    │    
                  ╰──────────────╰──────────────╯    

OptionalSequence

1 2 3
Text version
    ╭───────────╮─────────────╮              
    │  ╭───╮    │  ╭───╮      │  ╭───╮       
├┼──╯──│ 1 │──╮─╰──│ 2 │──╭─╮─╰──│ 3 │──╭──┼┤
       ╰───╯  │    ╰───╯  │ │    ╰───╯  │    
              ╰───────────╯ ╰───────────╯    

AlternatingSequence

foo bar
Text version
        ╭─────╮        
     ╭──│ foo │──╮     
     │  ╰─────╯  │     
    ╭╰────╮ ╭────╯╮    
├┼──┤      ╳      ├──┼┤
    ╰╭────╯ ╰────╮╯    
     │  ╭─────╮  │     
     ╰──│ bar │──╯     
        ╰─────╯        

MultipleChoice

1 2 3 take all branches, once each, in any orderall↺
Text version
                 ╭───╮               
              ╭──│ 1 │──╮            
              │  ╰───╯  │            
              │         │            
      ┌─────┐ │  ╭───╮  │ ┌───┐      
├┼────│ all │─┼──│ 2 │──┼─│ ↺ │────┼┤
      └─────┘ │  ╰───╯  │ └───┘      
              │         │            
              │  ╭───╮  │            
              ╰──│ 3 │──╯            
                 ╰───╯               

Start

Labeled Start 1 2 3
Text version
Labeled Start     ╭───╮     ╭───╮     ╭───╮       
├┼────────────────│ 1 │─────│ 2 │─────│ 3 │─────┼┤
                  ╰───╯     ╰───╯     ╰───╯       

Comment

/* anything but * followed by / */
Text version
               ╭────────────────────────────────────────╮               
               │                                        │               
      ╭────╮   │    ┌──────────────────────────────┐    │   ╭────╮      
├┼────│ /* │───╯─╭──│ anything but * followed by / │──╮─╰───│ */ │────┼┤
      ╰────╯     │  └──────────────────────────────┘  │     ╰────╯      
                 ╰────────────────────────────────────╯                 

ComplexDiagram

item
Text version
     ╭──────╮     
├────│ item │────┤
     ╰──────╯     

Block

Text version
      ┌──┐      
├┼────│  │────┼┤
      └──┘      

Repeat

item 2–4 times ,
Text version
        ╭──────╮                    
├┼───╭──│ item │──────────────╮───┼┤
     │  ╰──────╯              │     
     │                ╭───╮   │     
     ╰───2–4 times────│ , │───╯     
                      ╰───╯         

SeparatedList

item ,
Text version
        ╭──────╮        
├┼───╭──│ item │──╮───┼┤
     │  ╰──────╯  │     
     │  ╭───╮     │     
     ╰──│ , │─────╯     
        ╰───╯           

Except

letter except “[0-9]”
Text version
                            
       except “[0-9]”       
      ╭┄┄┄┄┄┄┄┄┄┄┄┄┄┄╮      
      ┆  ╭────────╮  ┆      
├┼────┼──│ letter │──┼────┼┤
      ┆  ╰────────╯  ┆      
      ╰┄┄┄┄┄┄┄┄┄┄┄┄┄┄╯      

CharClass

[a-z]
Text version
      ╭───────╮      
├┼────│ [a-z] │────┼┤
      ╰───────╯      

Special

any character
Text version
      ┌───────────────┐      
├┼────│ any character │────┼┤
      └───────────────┘      

Diagram

item
Text version
      ╭──────╮      
├┼────│ item │────┼┤
      ╰──────╯      

Terminal

literal
Text version
      ╭─────────╮      
├┼────│ literal │────┼┤
      ╰─────────╯      

NonTerminal

rule
Text version
      ┌──────┐      
├┼────│ rule │────┼┤
      └──────┘      

Skip

Text version
├┼─────┼┤

End

Text version
├┼───┼┤