There was a similar question a few days ago: What is a good tool for creating railroad diagrams?
That question was about how railroad diagrams in the SQLite syntax diagrams were generated. The accepted answer found that the diagrams were generated using a DSL written in Tcl.
Another answer offered a suggestion to use a diagram generator which works off of EBNL grammar.