Example Project Using StringTemplate with ANTLR4

834 views
Skip to first unread message

Colin Fraizer

unread,
Jan 26, 2015, 9:17:37 AM1/26/15
to stringtempla...@googlegroups.com
Can someone point me to an open-source project that uses ANTLR version 4 and StringTemplate to output programming language text? Something like a translator from (I hope) a simple programming language to another programming language would be ideal.

Thanks,
--Colin Fraizer

Terence Parr

unread,
Jan 26, 2015, 1:38:50 PM1/26/15
to stringtempla...@googlegroups.com
ANTLR itself? ;) Actually, most of the grammars are written in version 3 but it does use ST 4. Unfortunately it is a complicated beast. This is really a question about using ST 4; hooking it into ANTLR just means adding code to create an render templates within listener or visitor methods.


Ter
> --
> You received this message because you are subscribed to the Google Groups "stringtemplate-discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stringtemplate-dis...@googlegroups.com.
> To post to this group, send email to stringtempla...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/stringtemplate-discussion/b51291b6-871e-4fe6-8ba7-9a277c0aed08%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

José San Leandro

unread,
Feb 19, 2015, 10:36:29 AM2/19/15
to stringtempla...@googlegroups.com
Hi,

Mine (QueryJ) is not simple either, but it uses ANTLR4 and ST. Basically, it is a meta-framework to generate code from database schemas, using user-provided StringTemplate files. Such templates have some metadata associated, which is defined using a simple ANTLR4-based DSL.

For example, the metadata [1] for a template called PerCustomResultTemplateBuildHandler [2], implemented a trivial ANTLR4 grammar [3], is:

/*
 * PerCustomResultTemplatesFeature template metadata.
 */
// The template name (the filename).
name : PerCustomResultTemplatesFeature.stg;

// The type of template: per-table, per-repository, per-foreign-key, per-custom-result, per-custom-sql.
type : per-custom-result;

// The output flavor.
output: Cucumber;

// The filename builder.
filename  builder : PerCustomResultTemplateBuildHandler.java;

// The package.
package: org.acmsl.queryj.templates.handlers;

Don't get confused by the details. Basically, parsing the .def files helps me find all available templates, and know how to instantiate them and write their output to disk.


Reply all
Reply to author
Forward
0 new messages