StringTemplate design issues

Skip to end of sidebar
Go to start of sidebar
Skip to end of metadata
Go to start of metadata

Design issues encountered or susepected.

Expression formatting challenges

Example: leftpad or rightpad of expressions. Useful for aligning columns of items in source code, for example.

  • There is no in-built functionality to do this
  • The recommendation is to use an Attribute Renderer using the format option (to specify format args from the template)
    • But this requires setting that up in the java portion of the application.
    • It has to be done per class of the value supplied to the attribute.
      • Not even sure how that works for String type. Does one set a renderer for String? What if there needs to be a second renderer for strings?
      • If an attribute gets its value from a non-String, then String's renderer won't apply, So then nest that in another template? Is the output from a template always a String?

Overall, this seems like a much too convoluted way to accomplish really simple view-specific functions.

Per-template expression delimiters

So far as I can see in the StringTemplate class source code, StringTemplates always adopt the lexer of the STG they belong to. Even in the case of using the ST ctor that allows spec of specific lexer, that prompts creation of a unique STG just for this ST, and the STG gets set with the desired lexer.

So it appears that it's impossible for a StringTemplateGroup to be created with a different lexer for different templates. This in turn obstructs scenarios where one language is to be embedded within another. Example: generating code where the enclosing language is Java code, which will have statements in it containing Strings containing code in another language where a different delimiter would be more suitable.

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.