Questions tagged [stringtemplate-4]

StringTemplate is a java template engine

StringTemplate is a java template engine (with ports for C#, Python) for generating source code, web pages, emails, or any other formatted text output. StringTemplate is particularly good at code generators, multiple site skins, and internationalization / localization. StringTemplate also generates this website and powers ANTLR.

137 questions
1
vote
1 answer

StringTemplate4 - Storing attribute value in variable

I am injecting an attribute into my StringTemplate4 template which has multiple levels of sub-attributes. As I work through the template outputting various elements of it I need to refer to attributes quite far down in the nesting at differing…
John Bartlett
  • 370
  • 1
  • 3
  • 13
1
vote
2 answers

Weird NullPointerException in StringTemplate map operation

This is my StringTemplate template for generating import statements, which does map operation on the anonymous template {i | import ;<\n>} for every value in imports . importdecl(imports) ::= " ;<\n>}>…
scarecrow
  • 6,624
  • 5
  • 20
  • 39
1
vote
1 answer

Is there any way to suppress attribute a isn't defined error in stringTemplate?

When setting up a template, if the attribute keys are not set into the ST object it throws the error : context [anonymous] 11:27 attribute isn't defined is there any way to suppress this error or flag to not to show error in logs.i'm…
salauddin
  • 113
  • 8
1
vote
1 answer

Creating custom delimiter in stringtemplate

String Template uses <...> or $...$ as delimiters. I need to have a custom delimiter, something like <<...>>. Is this possible? The code below accepts only character for the start and end delimiters: ST st = new ST("<< token >>", '<<', '>>');
Rajagopal
  • 931
  • 1
  • 8
  • 23
1
vote
1 answer

How do you reset an `ST` instance in `StringTemplate4`?

StringTemplate instances in version 3 had a .reset() method. I am generating inside a for/each loop and want to reset the instance to its default state at the end of each loop. I have searched the JavaDoc and can not find out how to reset an…
user177800
1
vote
1 answer

Constructing AST in ANTLR version4

I am developing a compiler and have already implemented lexer, parser and semantic analyzer(using listener and visitor) using ANTLR4. For code generation I am planning to generate LLVM IR using StringTemplate(ST). To do so I am thinking of first…
1
vote
1 answer

I need to compare property values in StringTemplate

I have a list of tuples that I need to emit a C-like boolean expression from: ranges = [('a','z'),('0','9'),('_','_')] my template: "$ranges:{'$it.0$'<=c&&c<='$it.1$'}; separator='||'$" this…
akonsu
  • 28,824
  • 33
  • 119
  • 194
1
vote
1 answer

ANTLR 4 and StringTemplate 4 - using tree walker with templates

Disclaimer: I never used Java before last month, and I had never heard of ANTLR or StringTemplate before then either. For my internship this summer I was given a project using tools that nobody else at the company has ever used. Everyone "has faith…
Shelby S.
  • 157
  • 1
  • 5
  • 16
1
vote
1 answer

Trouble using TemplateGroupDirectory

I want to put several template files on a directory named "Templates", relative to the executable of my application, and use them. One template file, for instance, is named "Globals.st". That way, I created a TemplateGroupDirectory and loaded the…
Nilo Paim
  • 428
  • 6
  • 22
1
vote
1 answer

Using comma as list separator with StringTemplate 4

I need to create a comma-separated list of items: $subjects : {sub | $sub.Name$}separator=", "$ This does not seem to work. What is the right way to use a separator? Is there an alternative way to create a comma-separated list of…
Mayuri
  • 37
  • 5
1
vote
2 answers

embed java code inside a template

Is it possible to embed executable java code inside a ST4 template? eg if I want to pass a string to my template, which sometimes prints the string as-is, and sometimes prints it in caps, so I want a java code to do the necessary conversion. Without…
R71
  • 4,283
  • 7
  • 32
  • 60
1
vote
1 answer

how to generate multi-line comment

In stringtemplate-4, how to generate a multi-line comment? For example, the template is like this (the comment's start and end are in some other template): test(DESCRIPTION) ::= << * * * >> And DESCRIPTION is a long string, and may…
R71
  • 4,283
  • 7
  • 32
  • 60
1
vote
0 answers

Is there a concise way to reference a property of a property in StringTemplate

I find myself wanting to write to apply a template to a list in a property of a property. To do this, I have to make two levels of template: I have to invoke the outer one on prop1 and and then have it process the next…
bmargulies
  • 97,814
  • 39
  • 186
  • 310
1
vote
1 answer

How to use compiled templates?

I found on StringTemplate pages some reference to template compilation (http://www.stringtemplate.org/api/org/stringtemplate/v4/compiler/Compiler.html). The info is rather, let's say, lapidary. I cannot find any description/tutorial/example on why…
gruby karol
  • 329
  • 2
  • 11
1
vote
1 answer

Can you prevent StringTemplate output to stderr?

Im currently using the following to output to a servlet using StringTemplate: (ST)page.render(); When I do this, StringTemplate prints warnings to Stderr; filling up log files with useless warnings is not ideal. If I understand the documentation…
Jay
  • 19,649
  • 38
  • 121
  • 184