Skip to content

lukaslueg/railroad_dsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A small DSL to generate syntax diagrams using this library.

Crates.io Version Build status

  • {...} is a horizontal stack of connected elements
  • [...] is a vertical sequence of connected elements
  • <...> is a choice of multiple options, exactly one of which has to be picked
  • "foobar" is a terminal
  • 'foobar' is a non-terminal
  • `foobar` is a comment
  • ...? is an optional element
  • ...*... is a repeated element
  • ! is the empty element

Quotes (and backslashes) can be escaped using backslashes.

For example:

{["CONSTRAINT" "name"]?,
 <["PRIMARY" "KEY" <!, "ASC", "DESC"> 'conflict-clause' <!, "AUTOINCREMENT">],
  ["NOT" "NULL" 'conflict-clause'],
  ["UNIQUE" 'conflict-clause'],
  ["CHECK" "(" 'expr' ")"],
  ["DEFAULT" <'signed-number', 'literal-value', ["(" 'expr' ")"]>],
  ["COLLATE" "collation-name"],
  'foreign-key-clause'>}

diagram for constraint syntax

{[`create-table-stmt` "CREATE" <!, <"TEMP", "TEMPORARY">#`Table will be dropped when connection closes`> "TABLE"],
 [[["IF" "NOT" "EXISTS"]#`If table exists, do nothing`]? [[["schema-name" "."]#`...in a foreign database`]? "table-name"]#`The table's name`],
 [<["(" ['column-def'*","]#`One or more column-definitions` [!*[['table-constraint' ","]#`primary key and stuff`]]#`Zero or more table-constraints` ")" <!, ["WITHOUT" "ROWID"]>],
   ["AS" 'select-stmt']#`Create table definition and content directly from a query`>]}

diagram for create-table syntax

Run cargo run --example example_diagrams for more examples.


A small DSL to generate syntax-diagrams.

If no input files are given, act as a pipe from stdin to stdout. Otherwise, process each input file into an output file with the file extension replaced

Usage: railroad [OPTIONS] [INPUTS]...

Arguments:
  [INPUTS]...
          

Options:
      --css <CSS>
          Alternative CSS file

      --format <FORMAT>
          Output format
          
          [default: svg]
          [possible values: svg, png]

      --max-width <MAX_WIDTH>
          Maximum width of the final image

      --max-height <MAX_HEIGHT>
          Maximum height of the final image

      --theme <THEME>
          Theme to use
          
          [default: light]
          [possible values: light, dark]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

About

A small DSL to generate syntax diagrams

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages