I’m looking at pragmatically translating huge amounts of relatively simple TSQL code to Groovy code. There are a number of reasons sure, but the driving reason is just to see if it can be done and in the process learn about compilers/grammers/ etc.
Antlr4 seems like the ideal tool for this problem (Java is a plus).
Tokenizing / parsing the TSQL (using a grammar file), and reading the tree using the generated Listener/Visitor is pretty straight forward.
I know I could just create the string representation of the Groovy code inside of my inherited visitor, but coupling the matching Groovy token values with my TSQLVisitor doesn’t seem like the cleanest solution.
What would be considered the best practice here? and in general for mapping one language to another in Antlr4 ?
Things I’m considering:
- Using StringTemplate, and defining my groovy code in an STG file (my TSQLVisitor would use these templates and return the full string representation of the Groovy code).
- Switch to Antlr3 which supports adding StringTemplate logic directly into the Grammar file.