-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Description
Would be nice if this Grammar-Kit
added an option to dump the grammar in an EBNF
format understood by https://github.com/GuntherRademacher/rr to generate nice navigable railroad diagrams to hep document/develop/debug grammars.
I've also added https://github.com/JetBrains/Grammar-Kit/blob/master/grammars/Grammar.bnf to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex
like online interpreter/editor (select Grammar-Kit parser
from Examples
then click Parse
to see a parse tree for the content in Input source
) and from there I generated an EBNF
for railroad diagram (see bellow with instructions at the top).
//
// EBNF to be viewd at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one of the urls shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//
grammar::=
grammar_element
grammar_element::=
attrs
| rule
| grammar_element attrs
| grammar_element rule
rule::=
rule_start expression attrs_opt semi_opt
semi_opt::=
/*%empty*/
| SEMICOLON
attrs_opt::=
/*%empty*/
| attrs
rule_start::=
modifier_zom RULE_NAME OP_IS
modifier_zom::=
/*%empty*/
| modifier_zom modifier
modifier::=
"private"
| "external"
| "meta"
| "inner"
| "left"
| "upper"
| "fake"
attrs::=
LEFT_BRACE attr_zom RIGHT_BRACE
attr_zom::=
/*%empty*/
| attr_zom attr
attr::=
attr_start attr_value semi_opt
attr_start::=
id attr_pattern OP_EQ
| id OP_EQ
attr_value::=
attr_value_inner
attr_value_inner::=
reference_or_token
| literal_expression
| value_list
attr_pattern::=
LEFT_PAREN string_literal_expression RIGHT_PAREN
value_list::=
LEFT_BRACKET list_entry_zom RIGHT_BRACKET
list_entry_zom::=
/*%empty*/
| list_entry_zom list_entry
list_entry::=
id list_entry_tail_opt semi_opt
| string_literal_expression semi_opt
list_entry_tail_opt::=
/*%empty*/
| list_entry_tail
list_entry_tail::=
OP_EQ string_literal_expression
expression::=
sequence choice_opt
choice_opt::=
/*%empty*/
| choice
sequence::=
option_zom
option_zom::=
/*%empty*/
| option_zom option
option::=
predicate
| paren_opt_expression
| simple quantified_opt
quantified_opt::=
/*%empty*/
| quantified
choice::=
OP_OR sequence
| choice OP_OR sequence
quantified::=
quantifier
quantifier::=
OP_OPT
| OP_ONEMORE
| OP_ZEROMORE
predicate::=
predicate_sign simple
predicate_sign::=
OP_AND
| OP_NOT
simple::=
reference_or_token
| literal_expression
| external_expression
| paren_expression
external_expression::=
EXTERNAL_START reference_or_token option_zom EXTERNAL_END
reference_or_token::=
id
literal_expression::=
string_literal_expression
| number
string_literal_expression::=
string
paren_expression::=
LEFT_PAREN expression RIGHT_PAREN
paren_opt_expression::=
LEFT_BRACKET expression RIGHT_BRACKET
//Tokens
OP_IS ::= "::="
OP_NOT ::= "!"
OP_AND ::= "&"
LEFT_PAREN ::= "("
RIGHT_PAREN ::= ")"
OP_ZEROMORE ::= "*"
OP_ONEMORE ::= "+"
SEMICOLON ::= ";"
EXTERNAL_START ::= "<<"
OP_EQ ::= "="
EXTERNAL_END ::= ">>"
OP_OPT ::= "?"
LEFT_BRACKET ::= "["
RIGHT_BRACKET ::= "]"
LEFT_BRACE ::= "{"
OP_OR ::= "|"
RIGHT_BRACE ::= "}"
number ::= [0-9]+
string ::= "'"("\".|[^'\#xA#xD])*"'"
string ::= '"'("\".|[^"\#xA#xD])*'"'
RULE_NAME ::= id
id ::= [A-Za-z_][A-Za-z0-9_-]*
halirutan
Metadata
Metadata
Assignees
Labels
No labels