...
A simple java program to use this script template group would look as follows:
No Format |
---|
import java.io.File;
import java.io.FileReader;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.language.DefaultTemplateLexer;
public class t {
/* Quick and very nasty example: */
public static void main(String[] args)
throws Exception
{
File templateFileName = new File("te.stg");
StringTemplateGroup group = new StringTemplateGroup(
new FileReader(templateFileName),
DefaultTemplateLexer.class // Leave away if you want to use angle brace notation
);
StringTemplate template = group.getInstanceOf("variable");
template.setAttribute("type", "Integer");
template.setAttribute("name", "id");
System.out.println(template.toString());
}
}
|
And the output should look as follows:
No Format |
---|
<b>Integer</b> ID = 0;¶
|