Mirror
Mirror copied to clipboard
Grammar railroad diagram
Using an EBNF understood by https://github.com/GuntherRademacher/rr we can generate a nice navigable railroad diagram to help document/develop/debug the grammar (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 for Mirror.
program ::= (signature | example | expression)*
signature ::= "signature" name "(" parameters ")" "->" type
example ::= "example" name "(" literals ")" "=" literal
expression ::= name "(" subexpression ")"
subexpression ::= (expression | literal) ("," (expression | literal))*
literals ::= literal ("," literal)*
literal ::= string | number | "true" | "false" | "[" literals "]" | "{" keyvalue ("," keyvalue)* "}"
keyvalue ::= literal ":" literal
parameters ::= parameter ("," parameter)*
parameter ::= name ":" type
type ::= "string" | "number" | "bool" | "list[" type "]" | "dict[" type "," type "]"
// name, string, number are tokens
name ::= [Z-Za-z_][Z-Za-z0-9_]*
string ::= "'"[^']*"'" | '"'[^"]*'"'
number ::= [0-9]+("."[0-9]+)?