Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Java

Code Block
StringTemplateGroup group =
  new StringTemplateGroup("sqlstuff", "/tmp", AngleBracketTemplateLexer.class);
StringTemplate query =
  new StringTemplate(group, "SELECT <column> FROM <table>;");
query.setAttribute("column", "name");
query.setAttribute("table", "User");

C#

Code Block
StringTemplateGroup group =
     new StringTemplateGroup("sqlstuff", "/tmp", typeof(AngleBracketTemplateLexer));
StringTemplate query = new StringTemplate(group, "SELECT <column> FROM <table>;");
query.SetAttribute("column", "name");
query.SetAttribute("table", "User");

Python

Code Block
group = stringtemplatestringtemplate3.StringTemplateGroup("sqlstuff", "/tmp", \
            stringtemplate.language.AngleBracketTemplateLexer.Lexerlexer="angle-bracket")
query = stringtemplatestringtemplate3.StringTemplate(group, "SELECT <column> FROM <table>;", group=group)
query["column"] = "name"
query["table"] = "User"

Python accepts either a antlr.CharScanner class (stringtemplate3.language.DefaultTemplateLexer.Lexer, stringtemplate3.language.AngleBracketTemplateLexer.Lexer or your own implementation) or the string literals 'default' and 'angle-bracket'. Also note the use of the keyword argument lexer.

All templates created through the group or in anyway associated with the group will assume your the angle bracket delimiters. It's smart to be consistent across all files of similar type such as "all HTML templates use $...$" and "all SQL templates use <...>".