stringtemplate4 icon indicating copy to clipboard operation
stringtemplate4 copied to clipboard

Named parameters not support on dynamic template invocations.

Open rupertlssmith opened this issue 11 years ago • 2 comments

I'm using stringtemplate 4.0.8.

I'm having a problem passing a named argument to a template which has been looked up in a dictionary. Here is the offending line of code:

public <name; format="ccu">(<fields:{it|<(typeMap.(fields.(it).kind))(field=fields.(it))> <it; format="cc">}; separator=", ">) {

With (field=fields.(it)) passing field names to a template that has been looked up in a dictionary, so that fields can be rendered in different ways in different situations by substituting in different dictionaries.

On the cheat sheet, the documentation for <(expr)(argument-list)> says:

The argument-list is a list of attribute expressions or attribute assignments where each assignment is of the form attribute=expr.

Making it quite clear that attribute=expr is allowed. This worked on StringTemplate 3, but does not appear to be working on 4.

rupertlssmith avatar Feb 18 '15 10:02 rupertlssmith

This falls into the same category as indirect pass-through (e.g. <(expr)(...)>). StringTemplate 4 uses a bytecode interpreter instead of the AST interpreter in StringTemplate 3. Since the bytecode format cannot assign "names" to elements on the evaluation stack, there is no way to represent the concept of dynamically passing arguments by name.

To date, this has been a known limitation which was accepted due to StringTemplate 4's tremendous performance advantage over StringTemplate 3. However, since I don't see another feature request covering this topic on this issue tracker (only some old emails on the mailing list), I'm going to leave this open in case someone decides to work on a solution in the future.

sharwell avatar Feb 19 '15 13:02 sharwell

I see. It would be worth updating the the cheat sheet to mention this limitation though.

rupertlssmith avatar Feb 19 '15 13:02 rupertlssmith