I want to export ANTLR4 rules in the railroad format.
Please notice that this format is not the same as generated by command line option "-atn".
The railroad format is generated by antlrworks, but I'd like to generate this programatically.
I am looking for something like http://clapham.sourceforge.net/
clapham generates what I want from BNF. Is there any tool to convert from antlr4 to BNF? (question probably related to Generate BNF diagrams from an antlr grammar?, but notice I am not asking the same thing here. Converting to BNF is just a workaround, what I want is to generate the railroad diagram directly from ANTLR grammar)
Following the answer for Generate BNF diagrams from an antlr grammar? worked for me
Just get your ANTLR grammar, send to https://www.bottlecaps.de/convert/ and then to https://www.bottlecaps.de/rr/ui
ANTLR4 expressions such as "WS : [ \t\r\n]+ -> skip;" could not be processed so I've changed to the traditional form "WS ::= ( #x9 | #xD | #xA )*"
Clapham could not work with the BNF grammar generated by https://www.bottlecaps.de/convert/ unfortunately.
This is a way to get the diagram, but this is not programatically. I wish I had some JAR I could just add to generate on the fly.
Checkout ANTLR 4 IDE: https://github.com/jknack/antlr4ide
Here is a Java.g4 to HTML example: http://jknack.github.io/antlr4ide/Java/Javav4.g4.html
You will find images under the http://jknack.github.io/antlr4ide/Java/images directory.
The last update to this tool was in December 2016.