### Declaring and initializing templates in a directory Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Example of creating a STGroupDir, getting a template instance, adding attributes, and rendering the template. ```java STGroup group = new STGroupDir("/tmp"); ST st = group.getInstanceOf("decl"); st.add("type", "int"); st.add("name", "x"); st.add("value", 0); String result = st.render(); // yields "int x = 0;" ``` -------------------------------- ### Hello World example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md A simple StringTemplate example demonstrating how to create a template, add an attribute, and render it to produce 'Hello, World'. ```java import org.stringtemplate.v4.*; ... ST hello = new ST("Hello, "); hello.add("name", "World"); System.out.println(hello.render()); ``` -------------------------------- ### Slist template example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/indent.md An example of a StringTemplate template demonstrating auto-indentation. ```stringtemplate slist(statements) ::= << { } >> ``` -------------------------------- ### Dictionary Definition Example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/groups.md An example of a dictionary mapping Java type names to their default initialization values. ```antlr typeInitMap ::= [ "int":"0", "long":"0", "float":"0.0", "double":"0.0", "boolean":"false", "byte":"0", "short":"0", "char":"0", default:"null" // anything other than an atomic type ] ``` -------------------------------- ### Mythical Java-based template engine example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/motivation.md An example of a simple web page template using a mythical Java-based template engine, illustrating the pull method of attribute evaluation. ```html
    $foreach n in names
  1. $n
  2. $end
There are $numberNames names. ``` -------------------------------- ### Hello World Example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md A simple Java program to demonstrate basic StringTemplate usage. ```java import org.stringtemplate.v4.*; public class Hello { public static void main(String[] args) { ST hello = new ST("Hello, "); hello.add("name", "World"); System.out.println(hello.render()); } } ``` -------------------------------- ### Default arguments example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/3to4.md Example of default arguments in StringTemplate 4, where default arguments can access other arguments. ```antlr t(x,y={}>},z="foo") ::= <<...>> ``` -------------------------------- ### Dictionary Usage Example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/groups.md How to refer to dictionary entries within a template. ```antlr ``` -------------------------------- ### Aggregating data with addAggr Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Example demonstrating how to use addAggr to create data aggregates with specified properties. ```java ST st = new ST(": , \n}>"); st.addAggr("items.{ firstName ,lastName, id }", "Ter", "Parr", 99); // add() uses varargs st.addAggr("items.{firstName, lastName ,id}", "Tom", "Burns", 34); String expecting = "99: Parr, Ter\n"+ "34: Burns, Tom\n" ``` -------------------------------- ### Example 1: Custom UserAdaptor Source: https://github.com/antlr/stringtemplate4/blob/master/doc/adaptors.md This example demonstrates a custom UserAdaptor that handles specific properties ('id' and 'name') for a User class, which has private fields and a non-standard getter name ('theName'). ```java class UserAdaptor implements ModelAdaptor { public Object getProperty(Interpreter interpreter, ST self, User model, Object property, String propertyName) throws STNoSuchPropertyException { if ( propertyName.equals("id") ) return model.id; if ( propertyName.equals("name") ) return model.theName(); throw new STNoSuchPropertyException(null, "User."+propertyName); } } public static class User { private int id; // ST can't see; it's private private String name; public User(int id, String name) { this.id = id; this.name = name; } public String theName() { return name; } // doesn't follow naming conventions } ``` -------------------------------- ### Using STGroupFile for template group files Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Example of creating an STGroupFile from a .stg file and rendering a template. ```java STGroup group = new STGroupFile("/tmp/test.stg"); ST st = group.getInstanceOf("decl"); st.add("type", "int"); st.add("name", "x"); st.add("value", 0); String result = st.render(); // yields "int x = 0;" ``` -------------------------------- ### Separator with template invocation example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/expr-options.md Shows an example of using a template invocation as a separator. ```stringtemplate $name; separator=bulletSeparator(foo=" ")+" $" ``` -------------------------------- ### Renderer Registration Examples Source: https://github.com/antlr/stringtemplate4/blob/master/doc/renderers.md Demonstrates valid and invalid registrations of AttributeRenderers. ```Java STGroup g = ...; g.registerRenderer(Number.class, new NumberRenderer()); // ok g.registerRenderer(Integer.class, new NumberRenderer()); // ok g.registerRenderer(Double.class, new NumberRenderer()); // ok g.registerRenderer(String.class, new NumberRenderer()); // error ``` -------------------------------- ### Attribute resolution example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/inspector.md An example demonstrating how an attribute 'labelType' is resolved through dynamic scoping. ```antlr (!=null?(().start):null) ``` -------------------------------- ### General use of ST.format() Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Example of using the ST.format() method for general-purpose text formatting with an array of integers. ```java int[] num = new int[] {3,9,20,2,1,4,6,32,5,6,77,888,2,1,6,32,5,6,77, 4,9,20,2,1,4,63,9,20,2,1,4,6,32,5,6,77,6,32,5,6,77, 3,9,20,2,1,4,6,32,5,6,77,888,1,6,32,5}; String t = ST.format(30, "int <%1>[] = { <%2; wrap, anchor, separator=\", \"> };", "a", num); System.out.println(t); ``` -------------------------------- ### Anonymous templates (subtemplates) Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Example of using an anonymous template for inline formatting. ```stringtemplate test(name) ::= "]}; separator=\", \">" ``` -------------------------------- ### Loading Group from Strings Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Example of creating a StringTemplate group from a Java string. ```java String g = "a(x) ::= <>\n"+ "b() ::= <>\n"; STGroup group = new STGroupString(g); ST st = group.getInstanceOf("a"); String expected = "foo"; String result = st.render(); assertEquals(expected, result); ``` -------------------------------- ### Maven settings.xml file permissions Source: https://github.com/antlr/stringtemplate4/blob/master/doc/releasing-st4.md Example of checking the file permissions for the Maven settings.xml file on a Unix-like system. ```bash beast:~/.m2 $ ls -l settings.xml -rw------- 1 parrt staff 914 Jul 15 14:42 settings.xml ``` -------------------------------- ### List construction examples Source: https://github.com/antlr/stringtemplate4/blob/master/doc/null-vs-empty.md Demonstrates list construction within ST expressions, including combining lists and handling missing elements. ```stringtemplate <[]> ``` ```stringtemplate <[]; null="x"> ``` ```stringtemplate <[[],[]]:{it | x}; separator=","> ``` ```stringtemplate <[]:t()> ``` ```stringtemplate <[]:{it | x}> ``` -------------------------------- ### Example of applying parens template to a list Source: https://github.com/antlr/stringtemplate4/blob/master/doc/templates.md Demonstrates the output of applying the 'parens' template to a list of strings. ```stringtemplate ["a", "b", "c"]:parens() ``` -------------------------------- ### Map lookup examples Source: https://github.com/antlr/stringtemplate4/blob/master/doc/null-vs-empty.md Illustrates how missing map entries are handled, evaluating to null and resulting in empty strings when used in expressions. ```stringtemplate d ::= [x:"x"] }> ``` ```stringtemplate d ::= [x:"x"] }> ``` -------------------------------- ### Loading Group File from Current Directory Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Example of loading a StringTemplate group file from the current directory. ```java //load file name STGroup g = new STGroupFile("test.stg"); ``` -------------------------------- ### Example 2: Usage Source: https://github.com/antlr/stringtemplate4/blob/master/doc/adaptors.md This code snippet demonstrates registering the UserAdaptor (inheriting from ObjectModelAdaptor) and rendering a template that utilizes the overridden and newly added properties. ```java String template = "foo(x) ::= \": ()\"\n"; STGroup g = new STGroupString(template); g.registerModelAdaptor(User.class, new UserAdaptor()); ST st = g.getInstanceOf("foo"); st.add("x", new User(100, "parrt")); String expecting = "100: Parrt (User object with id:100)"; String result = st.render(); ``` -------------------------------- ### Formal Argument Default Value Syntax Error Example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/release-notes/4.0.3.md An example demonstrating a bug fix related to NullPointerException when a formal argument's default value has a syntax error. ```stringtemplate main(a={(<"")>}) ::= "" ``` -------------------------------- ### Example of STRawGroupDir usage Source: https://github.com/antlr/stringtemplate4/blob/master/doc/release-notes/4.0.5.md Demonstrates how STRawGroupDir expects pure templates without headers, contrasting with the usual template definitions. ```java foo(name) ::= "$name" ``` -------------------------------- ### Launching the inspector and tracking events Source: https://github.com/antlr/stringtemplate4/blob/master/doc/inspector.md Example of how to launch the GUI inspector and enable tracking of template creation and attribute injection events. ```java STGroup.trackCreationEvents = true; STGroup group = new STGroupFile("t.stg"); ST st = group.getInstanceOf("test"); st.add("attrname", value); ... st.inspect(); ``` -------------------------------- ### Dynamic Inheritance Example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/inheritance.md Demonstrates how to dynamically import/inherit templates using the controller instead of an import statement in group files. ```java STGroup java1_4 = new STGroupFile("/tmp/Java1_4.stg"); STGroup java1_5 = new STGroupFile("/tmp/Java1_5.stg"); java1_5.imporTemplates(java1_4); // import "Java1_5.stg" STGroup dbg_java1_4 = new STGroupFile("/tmp/Dbg.stg"); STGroup dbg_java1_5 = new STGroupFile("/tmp/Dbg.stg"); dbg_java1_4.importTemplates(java1_4); // import "Java1_4.stg" dbg_java1_5.importTemplates(java1_5); // import "Java1_5.stg" ``` -------------------------------- ### Java template for a method Source: https://github.com/antlr/stringtemplate4/blob/master/doc/regions.md An example of a basic Java method template. ```stringtemplate // Java.stg method(name,code) ::= << public void () { } >> ``` -------------------------------- ### Default values for arguments Source: https://github.com/antlr/stringtemplate4/blob/master/doc/groups.md Example of a template defining default values for arguments. ```stringtemplate class(name,members,sup="Object") ::= "class extends { }" ``` -------------------------------- ### Loading Group Directory with Relative Path Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Example of loading StringTemplate templates from a directory using a relative path. ```java // load relative directory of templates STGroup g = new STGroupDir("templates"); ``` -------------------------------- ### Example 1: Usage Source: https://github.com/antlr/stringtemplate4/blob/master/doc/adaptors.md This code snippet shows how to register the custom UserAdaptor with an STGroup and use it to render a template with a User object. ```java String template = "foo(x) ::= \": \"\n"; STGroup g = new STGroupString(template); g.registerModelAdaptor(User.class, new UserAdaptor()); ST st = g.getInstanceOf("foo"); st.add("x", new User(100, "parrt")); String expecting = "100: parrt"; String result = st.render(); ``` -------------------------------- ### Update ST.java version Source: https://github.com/antlr/stringtemplate4/blob/master/doc/releasing-st4.md Example of how to change the static VERSION string in the ST.java file. ```java public final static String VERSION = "4.3.4"; ``` -------------------------------- ### Setting CLASSPATH for StringTemplate Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Example of how to set the CLASSPATH environment variable on UNIX to include the StringTemplate jar. ```bash $ export CLASSPATH="/usr/local/lib/ST-4.3.4.jar:$CLASSPATH" ``` -------------------------------- ### Null and separator option example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/expr-options.md Demonstrates how to use the null and separator options to format a list containing null values. ```stringtemplate $values; null="-1", separator=", $" ``` -------------------------------- ### Loading Group File with Relative Path Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Example of loading a StringTemplate group file using a relative path. ```java // load relative file name STGroup g = new STGroupFile("templates/test.stg"); ``` -------------------------------- ### Loading Group Directory with Fully Qualified Name Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Example of loading StringTemplate templates from a directory using a fully qualified path. ```java // load fully qualified directory of templates STGroup g = new STGroupDir("/usr/local/share/templates"); ``` -------------------------------- ### Registering and Using NumberRenderer Source: https://github.com/antlr/stringtemplate4/blob/master/doc/renderers.md Example of registering a NumberRenderer and using it with a template for Polish locale formatting. ```Java String template = "foo(x,y) ::= << >>\n"; STGroup g = new STGroupString(template); g.registerRenderer(Number.class, new NumberRenderer()); ST st = group.getInstanceOf("foo"); st.add("x", -2100); st.add("y", 3.14159); String result = st.render(new Locale("pl")); // resulted is " -2 100 3,142 " since Polish uses ' ' for ',' and ',' for '.' ``` -------------------------------- ### StringTemplate output from group inheritance example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/inheritance.md The rendered output from the Java code demonstrating group inheritance. ```text // StringTemplate output class T { public static final MyEnum_A=1; public static final MyEnum_B=2; } class T { public enum MyEnum { A, B } } ``` -------------------------------- ### Scala Case Classes Source: https://github.com/antlr/stringtemplate4/blob/master/doc/scala-model-adaptor.md Example of Scala case classes for Point and Triangle. ```scala case class Point(x: Int, y: Int) case class Triangle(p1: Point, p2: Point, p3: Point) ``` -------------------------------- ### Alternating list item colors Source: https://github.com/antlr/stringtemplate4/blob/master/doc/templates.md Example of using multiple templates in a round-robin fashion to alternate styling for list items. ```stringtemplate $names:blueListItem(),greenListItem()$ ``` -------------------------------- ### Loading Group File with Fully Qualified Name Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Example of loading a StringTemplate group file using a fully qualified path. ```java // load fully qualified file name STGroup g = new STGroupFile("/usr/local/share/templates/test.stg"); ``` -------------------------------- ### Adding attributes with notation Source: https://github.com/antlr/stringtemplate4/blob/master/doc/release-notes/4.0.1.md Example of using the new notation for injecting attributes. ```java st.add("users.{name,id}", "Ter", "parrt"); ``` -------------------------------- ### Accessing User object properties in a template Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Example of creating a StringTemplate with custom delimiters and injecting a User object to access its properties. ```java ST st = new ST("$u.id$: $u.name$", '$', '$'); st.add("u", new User(999, "parrt")); String result = st.render(); // "999: parrt" ``` -------------------------------- ### Inheritance with Directories Example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/inheritance.md Illustrates how StringTemplate handles inheritance when using directories of templates, and the restriction against mixing group files with imports within a STGroupDir. ```java STGroup dir = STGroupDir("/tmp"); dir.getInstanceOf("a"); // no problem; looks in "/tmp/a.st" dir.getInstanceOf("/foo/b"); // no problem if foo.stg has b() template ``` ```java import "bar.stg" // causes unsupported operation exception b() ::= "..." ``` ```java STGroup g = new STGroupFile("/tmp/foo.stg"); ``` -------------------------------- ### PointAdaptor and PointTest Example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/scala-model-adaptor.md Demonstrates extending ScalaModelAdaptor to customize property retrieval for a Point case class and testing the adaptor with StringTemplate4. ```scala class PointAdaptor extends ScalaModelAdaptor[Point] with ToJava { override def getProperty(interp: Interpreter, self: ST, model: Point, property: Any, propertyName: String): Object = { propertyName match { case "x" => s"x: ${super.getProperty(interp, self, model, property, propertyName)}" case "y" => s"y: ${super.getProperty(interp, self, model, property, propertyName)}" case "x_times" => val x = super.getProperty(interp, self, model, property, "x").asInstanceOf[Int] toObject(Seq.tabulate(x)(_ => model)) case _ => super.getProperty(interp, self, model, property, propertyName) } } } object PointTest extends App { val p = Point(2, 5) val group = { val template = """ |id(x) ::= \"\" |point(p) ::= << |( , ); |>>""".stripMargin val g = new STGroupString(template) g.registerModelAdaptor(classTag[Point].runtimeClass.asInstanceOf[Class[Point]], new PointAdaptor) g } group.getInstanceOf("point").add("p", p).render() // should render as: (x: 2, y: 5); Point(2,5), Point(2,5) } ``` -------------------------------- ### Group Definition Syntax Source: https://github.com/antlr/stringtemplate4/blob/master/doc/release-notes/4.0.md Example of the old style header syntax for group definitions, which can be used to support both v3 and v4 parsers. ```ANTLR oldStyleHeader // ignore but lets us use this parser in AW for both v3 and v4 : 'group' ID ( ':' ID )? ( 'implements' ID (',' ID)\* )? ';' ; ``` -------------------------------- ### <<<...>>> template Source: https://github.com/antlr/stringtemplate4/blob/master/CHANGES.txt Example of a template that ignores all \n inside; use <\n> to get one. ```stringtemplate <<<...>>> ``` -------------------------------- ### Compiling and Running Hello World Source: https://github.com/antlr/stringtemplate4/blob/master/doc/java.md Command-line instructions to compile and run the 'Hello World' Java program. ```bash /tmp $ javac Hello.java /tmp $ java Hello Hello, World ``` -------------------------------- ### Using STRawGroupDir for simpler template files Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Demonstrates how STRawGroupDir can be used when only the template text is needed, without formal definitions. ```java // file /tmp/decl.st ; ``` -------------------------------- ### Internal error message example Source: https://github.com/antlr/stringtemplate4/blob/master/doc/release-notes/4.0.1.md Example of an internal error message during template evaluation. ```text context [outputFile parser genericParser rule ruleBlockSingleAlt alt element ruleRefAndListLabel ruleRef] 1:1 internal error caused by: java.lang.NullPointerException at org.stringtemplate.v4.ST.rawSetAttribute(ST.java:294) at org.stringtemplate.v4.Interpreter.storeArgs(Interpreter.java:576) at org.stringtemplate.v4.Interpreter.super_new(Interpreter.java:495) ... ``` -------------------------------- ### Example 2: UserAdaptor inheriting from ObjectModelAdaptor Source: https://github.com/antlr/stringtemplate4/blob/master/doc/adaptors.md This example shows a UserAdaptor that extends ObjectModelAdaptor, overriding specific property handling (like 'name' to capitalize it) and adding new properties ('description'), while letting the superclass handle others ('id'). ```java class UserAdaptor extends ObjectModelAdaptor { public Object getProperty(Interpreter interpreter, ST self, User model, Object property, String propertyName) throws STNoSuchPropertyException { // intercept handling of "name" property and capitalize first character if ( propertyName.equals("name") ) return model.name.substring(0,1).toUpperCase()+model.name.substring(1); // respond to "description" property by composing desired result if ( propertyName.equals("description") ) return "User object with id:" + model.id; // let "id" be handled by ObjectModelAdaptor return super.getProperty(interpreter,self,model,property,propertyName); } } public static class User { public int id; // ST can see this and we'll let ObjectModelAdaptor handle it public String name; // ST can see this, but we'll override to capitalize public User(int id, String name) { this.id = id; this.name = name; } } ``` -------------------------------- ### Grammar Rule Example Source: https://github.com/antlr/stringtemplate4/blob/master/CHANGES.txt A grammar rule definition for StringTemplate. ```antlr : 'group' ID ( ':' ID )? ( 'implements' ID (',' ID)* )? ';' ; ``` -------------------------------- ### Rendering a template Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md The basic method call to render a StringTemplate template. ```java ST.render() ``` -------------------------------- ### Java 1.5 enum declaration Source: https://github.com/antlr/stringtemplate4/blob/master/doc/inheritance.md Example of declaring enums in Java 1.5. ```Java // Java 1.5 public enum MyEnum { A, B } ``` -------------------------------- ### Java 1.4 enum simulation Source: https://github.com/antlr/stringtemplate4/blob/master/doc/inheritance.md Example of simulating enums in Java 1.4. ```Java // Java 1.4 public static final int MyEnum_A = 1; public static final int MyEnum_B = 2; ``` -------------------------------- ### Applying templates to attributes Source: https://github.com/antlr/stringtemplate4/blob/master/doc/introduction.md Demonstrates applying a 'bracket' template to a list of names, with and without separators. ```stringtemplate test(name) ::= "" // apply bracket template to each name bracket(x) ::= "[]" // surround parameter with square brackets ``` ```stringtemplate test(name) ::= "" brakcet(x) ::= "[]" ``` -------------------------------- ### Disabling auto-indentation Source: https://github.com/antlr/stringtemplate4/blob/master/doc/indent.md Java code example showing how to disable auto-indentation by using NoIndentWriter. ```java StringWriter sw = new StringWriter(); NoIndentWriter w = new NoIndentWriter(sw); st.write(w); // same as render() except with a different writer String result = sw.toString(); ``` -------------------------------- ### Importing Templates and Groups (Absolute Paths) Source: https://github.com/antlr/stringtemplate4/blob/master/doc/groups.md Demonstrates importing single templates, group files, and directories using absolute paths. ```antlr // /tmp/main.stg import "/tmp/test.st" // import a single template import "/tmp/test.stg" // import a group of templates from a file import "/tmp/test" // import a directory of templates ``` -------------------------------- ### Forcing newline characters Source: https://github.com/antlr/stringtemplate4/blob/master/doc/3to4.md Example of how to force \r\n as a newline character using AutoIndentWriter. ```Java st.write(new AutoIndentWriter(sw,"\r\n")); // force \r\n as newline ``` -------------------------------- ### Chained add() calls Source: https://github.com/antlr/stringtemplate4/blob/master/CHANGES.txt Example demonstrating chained add() calls for adding attributes to a template. ```java t.add("x", 1).add("y", "hi"); ``` -------------------------------- ### Gradle Repositories Source: https://github.com/antlr/stringtemplate4/blob/master/README.md Ensure mavenCentral is included in your Gradle repositories. ```groovy repositories { // ... mavenCentral() } ``` -------------------------------- ### Maven release perform Source: https://github.com/antlr/stringtemplate4/blob/master/doc/releasing-st4.md Command to perform the Maven release, deploying the artifacts to the repository. ```bash mvn release:perform -Darguments="-DskipTests" ``` -------------------------------- ### Setting a listener per rendering Source: https://github.com/antlr/stringtemplate4/blob/master/doc/listeners.md Example of how to set an error listener for a specific StringTemplate instance during rendering. ```java // listener per rendering STGroup g = ...; ST st = g.getInstance("foo"); st.write(myWriter, myListener); ``` -------------------------------- ### Importing Templates and Groups (Relative Paths) Source: https://github.com/antlr/stringtemplate4/blob/master/doc/groups.md Illustrates importing using relative paths, which is more flexible. ```antlr // /tmp/main.stg import "test.st" // import a single template import "test.stg" // import a group of templates from a file import "test" // import a directory of templates ``` -------------------------------- ### Java Command Line for Benchmark Execution Source: https://github.com/antlr/stringtemplate4/blob/master/benchmark/org/stringtemplate/v4/benchmark/maniac.benchmark.txt The command used to execute the StringTemplate v4 benchmark suite, specifying the Java runtime, classpath, and the main benchmark class. ```bash /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java -Dfile.encoding=MacRoman -classpath /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/deploy.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/javaws.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/management-agent.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/plugin.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/sa-jdi.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/charsets.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/jconsole.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/management-agent.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/../Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/apple_provider.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/dnsns.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/localedata.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/sunjce_provider.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/sunpkcs11.jar:/Users/parrt/antlr/code/ST4/java/main/src:/Users/parrt/antlr/code/antlr/main/target:/Users/parrt/antlr/code/antlr/main/tool/src/main/resources:/Applications/IntelliJ IDEA 10.app/lib/junit-4.7.jar org.stringtemplate.v4.benchmark.Benchmark org.stringtemplate.v4.benchmark.Attributes org.stringtemplate.v4.benchmark.WriteFixedTemplates ``` -------------------------------- ### Maven settings.xml template Source: https://github.com/antlr/stringtemplate4/blob/master/doc/releasing-st4.md A template for the Maven settings.xml file, including server credentials and GPG key information for deployment. ```xml sonatype-nexus-staging sonatype-username XXX sonatype-nexus-snapshots sonatype-username XXX false UUU XXX ``` -------------------------------- ### Setting a listener per group Source: https://github.com/antlr/stringtemplate4/blob/master/doc/listeners.md Example of how to set an error listener for an entire StringTemplate group before processing templates. ```java // listener per group STGroup g = ...; g.setListener(myListener); g.getInstance("foo"); ... ``` -------------------------------- ### Indentation debugging event structure Source: https://github.com/antlr/stringtemplate4/blob/master/CHANGES.txt Example showing the structure of an indentation debugging event with AST node information. ```antlr ^(INDENT expr-sub-tree) is now ^(INDENTED_EXPR INDENT expr-sub-tree) ``` -------------------------------- ### t() ::= <% ... %> template Source: https://github.com/antlr/stringtemplate4/blob/master/CHANGES.txt Example of a template that ignores all newlines inside, useful for generating output on a single line. ```stringtemplate t() ::= <% ... %> ``` -------------------------------- ### Internal error during template evaluation Source: https://github.com/antlr/stringtemplate4/blob/master/CHANGES.txt Example of an internal error message during template evaluation, showing the stack trace. ```java context [outputFile parser genericParser rule ruleBlockSingleAlt alt element ruleRefAndListLabel ruleRef] 1:1 internal error caused by: java.lang.NullPointerException at org.stringtemplate.v4.ST.rawSetAttribute(ST.java:294) at org.stringtemplate.v4.Interpreter.storeArgs(Interpreter.java:576) at org.stringtemplate.v4.Interpreter.super_new(Interpreter.java:495) ... ``` -------------------------------- ### Maven release prepare Source: https://github.com/antlr/stringtemplate4/blob/master/doc/releasing-st4.md Command to prepare for a Maven release, which involves setting versions and SCM tags. ```bash mvn release:prepare -Darguments="-DskipTests" ```