jacquev6 / DrawGrammar

Draw railroad diagrams of EBNF grammars. In browser and on command line
http://jacquev6.github.io/DrawGrammar
56 stars 6 forks source link

Extract inlined rules #4

Open jacquev6 opened 6 years ago

jacquev6 commented 6 years ago

Some grammars have repetitions. Here is a benign example extracted from the OCaml manual:

\begin{syntax}
typexpr:
        '(' typexpr { ',' typexpr } ')' typeconstr
      | '(' typexpr { ',' typexpr } ')' '#' class-path
\end{syntax}

the '(' typexpr { ',' typexpr } ')' part is duplicated.

If the user adds a rule like:

\begin{syntax}
typexpr-tuple:
        '(' typexpr { ',' typexpr } ')'
\end{syntax}

DrawGrammar could allow her to "outline" it, i.e. draw typeexpr as if it was defined as:

\begin{syntax}
typexpr:
        typexpr-tuple typeconstr
      | typexpr-tuple '#' class-path
\end{syntax}

This is exactly the reverse of what we've done in #2.