Text elements¶
Text elements are single elements on the diagram and the base building blocks. They are either Expression, Terminal, NonTerminal, Comment, Arrow or Skip.
Expression¶
An expression is either a sub-diagram for a bigger diagram (typically, a clause in a grammar, which will appear as non-terminal in another part of the grammar), or something that the EBNF parser couldn't handle on its own (and will need a little help rewriting).
For exemple, the W3C blindfold grammar for EBNF is specified as follows:
grammar ::= clause* # A grammar is zero or more clauses
clause ::= clauseName "::=" pattern # A clause associates a name with a pattern
pattern ::= branch ("|" branch)* # A pattern has one or more branches (alternatives)
branch ::= term+ # A branch is one or more terms
term ::= # A term is:
string # a string in single or double quotes
| charset # a character set (as in perl: [a-z0-9], etc)
| "(" pattern ")" # a pattern, in parentheses
| clauseName # a clauseName, matching a pattern by name
| term [*+?] # a term followed by a "*", "+", or "?" operator
There are five expressions in that grammar, and running py-railroad on it produces the following diagrams:
In the last expression, the last element is [*+?] because the parser treated it as a character range and couldn't tell whether it was a finite list of characters (a Choice) or an actual range (ie. "all characters from a to z").
Syntax¶
Basic syntax:
With href:
With additional options:
Properties¶
Output¶
Terminal¶
Terminal represents literal text. The Terminal element has a required property text
, and three optional properties href
, title
and cls
. The last two properties are only available with the JSON and YAML parsers.
Syntax¶
Basic syntax:
With href:
With additional options:
Properties¶
- text: string, required
- href: string, optional
- title: string, optional, only available with the JSON and YAML parsers
- cls: string, optional, only available with the JSON and YAML parsers
Output¶
NonTerminal¶
NonTerminal represents another production or diagram. The NonTerminal element has a required property text
, and three optional properties href
, title
and cls
. The last two properties are only available with the JSON and YAML parsers.
Syntax¶
Basic syntax:
With href:
With additional options:
Properties¶
- text: string, required
- href: string, optional
- title: string, optional, only available with the JSON and YAML parsers
- cls: string, optional, only available with the JSON and YAML parsers
Output¶
Comment¶
Represents a comment. The Comment element has a required property text
, and three optional properties href
, title
and cls
. The last two properties are only available with the JSON and YAML parsers.
Syntax¶
Basic syntax:
With href:
With additional options:
Properties¶
- text: string, required
- href: string, optional
- title: string, optional, only available with the JSON and YAML parsers
- cls: string, optional, only available with the JSON and YAML parsers
Output¶
Arrow¶
Syntax¶
Arrow right:
With a direction:
Undirected (draws a line):
Properties¶
direction: optional string, can be left or right to orient the arrow left or right, or any other string to draw a plain line instead.
Output¶
Skip¶
An empty line. Used for vertical blocks like Stack.
Syntax¶
Properties¶
This element has no properties.