Protobuf target for antlr4

45 Views Asked by At

I have some project with antlr3 grammar, I managed to migrate it to antlr4 (antlr4 accepts it and generates code). But this project also uses this grammar to generate protobuf to implement some typing logic later. Actually, they pass some .stg file with grammar to antlr3 tool with option -language protobuf and receive desired .proto file. Is there any way to do something similar in antlr4?

The only way I see now is to add protobuf target as described here, but this requires changing source code. I just need to generate protobuf using project`s custom .stg file.

1

There are 1 best solutions below

0
Bart Kiers On

To make use of the -language protobuf command line option, you will need to adjust the tool itself. Otherwise, you'll need to get the parse tree that the ANTLR parser creates for you given your input source, and (through custom code) output the desired result (possibly based on the stg protobuf template). Either way, seems like a bit of work.