closed Could we add syntax diagrams?

+3 votes
asked Sep 21, 2022 in Wanted features by Todd Musheno (2,680 points)
closed Dec 5, 2022 by Todd Musheno

I would like to be able to generate syntax diagrams (also known as railroad diagrams):

https://en.wikipedia.org/wiki/Syntax_diagram

I would suggest starting with vanilla EBNF, as its the most widely used, and for most cases this should be "good enough".

A good site that can do this well is:

https://bottlecaps.de/rr/ui

Discussion might be good if you should support a whole syntax tree, or just one rule at a time.

I would LIKE to see support for a full syntax, but think single rule may be enough.

closed with the note: Good enough for beta
commented Nov 8, 2022 by Todd Musheno (2,680 points)

Outside documentation...

with https://forum.plantuml.net/16781/allow-special-sequence-management-special-sequence-symbol

I think we are now good for public "beta" release.

1 Answer

0 votes
answered Sep 21, 2022 by plantuml (294,540 points)

Sure, having support for https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form would be nice.

For example, we could have:

@startebnf
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
       | "H" | "I" | "J" | "K" | "L" | "M" | "N"
       | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
       | "V" | "W" | "X" | "Y" | "Z" | "a" | "b"
       | "c" | "d" | "e" | "f" | "g" | "h" | "i"
       | "j" | "k" | "l" | "m" | "n" | "o" | "p"
       | "q" | "r" | "s" | "t" | "u" | "v" | "w"
       | "x" | "y" | "z" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
symbol = "[" | "]" | "{" | "}" | "(" | ")" | "<" | ">"
       | "'" | '"' | "=" | "|" | "." | "," | ";" ;
character = letter | digit | symbol | "_" ;
 
identifier = letter , { letter | digit | "_" } ;
terminal = "'" , character , { character } , "'"
         | '"' , character , { character } , '"' ;
 
lhs = identifier ;
rhs = identifier
     | terminal
     | "[" , rhs , "]"
     | "{" , rhs , "}"
     | "(" , rhs , ")"
     | rhs , "|" , rhs
     | rhs , "," , rhs ;

rule = lhs , "=" , rhs , ";" ;
grammar = { rule } ;
@endebnf

The drawing part is easy.

The most complex part is parsing EBNF.
Unfortunately, we cannot find any easy to integrate and free Java EBNF parser and we don't really have time to write such a parser.

However, if anyone with Java skills is okay to write such a parser, we would be glad to implement the drawing part!

...