3 releases
Uses new Rust 2024
new 0.1.2 | Mar 6, 2025 |
---|---|
0.1.1 | Mar 4, 2025 |
0.1.0 | Mar 4, 2025 |
#2544 in Parser implementations
381 downloads per month
11KB
177 lines
EBNSF
Extended Backus-Naur Syntax FDiagrams
Create railroad diagrams from EBNF
Usage
Usage: ebnsf [OPTIONS] <INPUT>
Arguments:
<INPUT> File to read EBNF spec from
Options:
-o, --output <OUTPUT> Where to save the rendered SVG
-h, --help Print help
Example
Run ebnsf ./test/bnf.ebnf -o ./doc/bnf.svg
to turn
<syntax> ::= <rule>+
<rule> ::= <opt_whitespace> "<" <rule_name> ">" <opt_whitespace> "::=" <opt_whitespace> <group> <line_end>
<opt_whitespace> ::= " "*
<expression> ::= <list> (<opt_whitespace> "|" <opt_whitespace> <expression>)?
<group> ::= "(" <expression> ")" | <expression>
<line_end> ::= <opt_whitespace> "\n"+
<list> ::= <term> | <term> <opt_whitespace> <list>
<term> ::= <literal> | "<" <rule_name> ">"
<literal> ::= '"' <text> '"'
<text> ::= <character>+
<character> ::= <letter> | <digit>
<letter> ::= "[A-Za-z]"
<digit> ::= "[0-9]"
<rule_name> ::= <letter> <rule_char>*
<rule_char> ::= <letter> | <digit> | "_"
into
Todo
- support repitition specifiers and ranges (i.e. [a-z], +, *)
?
,+
, and*
now supported- ranges can be specified by cheating and treating them as literals, e.g. "[a-z]". first-class support for ranges without wrapping them in quotes will be added later (but they probably won't be validated).
- support grouping
- grouping now supported (with repitition modifiers) using parenthesis
- support rules spanning multiple lines
- decide on the full syntax I want to use/support for EBNF. See dwheeler.com, grammarware.net, w3.org, and cl.cam.ac.uk links below.
- figure out if/how I want to handle bounded repitition
- figure out if/how I want to handle negation
- support escape characters
- supports escaping nested quotes and backslashes
- decide what comment syntax to use
Credit
- Initial parser and
grammars/bnf.ebnf
file based on from BNF specification in EBNF form from https://bnfplayground.pauliankline.com/ > Examples > BNF grammars/semver.ebnf
from https://semver.org/spec/v2.0.0.html#backusnaur-form-grammar-for-valid-semver-versions
Additional reading on EBNF syntax:
Dependencies
~9MB
~172K SLoC