Open mingodad opened 2 years ago
Thanks for the contribution, @mingodad. A few questions need to be resolved before we move forward with this.
I'm not sure whether how this railroad diagram sits with the hand-curated grammar in https://github.com/hydromatic/morel/blob/main/docs/reference.md.
The hand-curated grammar doesn't have the extra symbols (e.g. type5, type6, type7) introduced to deal with precedence. It doesn't have the nice railroad arrows, but it's not difficult to read if you know BNF.
Also, going forward, I don't know how we would maintain the grammar.ebnf (by hand, or generate it from MorelParser.jj) and I don't know how we would generate grammar.xml (paste the grammar into the Railroad diagram generator site, download the XHTML file and commit, or generate using a maven plugin).
The EBNF grammar generated from the parser is meant to help understand/develop the parser, it's true that the parser can have some extra details to facilitate parsing but without any influence on the end user point of view.
There is allays the possibility of parser grammar and "hand-curated grammar" going out of sync, for the end user a pruned grammar is better but for the developer the full parser grammar is better.
Also because the tool makes some simplifications/optimizations it also help refactoring the grammar.
There is a possibility of generate the xhtml
diagram offline using the available downloadable java jar program from the front page at https://www.bottlecaps.de/rr/ui -> https://www.bottlecaps.de/rr/download/rr-1.63-java8.zip .
java -jar rr.war grammar.ebnf > grammar.ebnef.xhtml
With a custom parser to parse the JavaCC grammar for
morel
to produce an EBNF understood by https://www.bottlecaps.de/rr/ui we can have a nice railroad diagram (https://en.wikipedia.org/wiki/Syntax_diagram).I also did a reorder of the rules (reverse then) to get a better navigable railroad diagram, copy and paste the EBNF shown bellow at https://www.bottlecaps.de/rr/ui on the tab "Edit Grammar" then click on the tab "View Diagram".