Using GUIDs as attributes to substitute in a stringtemplate.org template

79 Views Asked by At

Is there a way in template (stringtemplate.org 4 engine) to use a GUID as an attribute to be substituted or to reduce stringtemplate's expressiveness so it will not evaluate the value between the delimiters as anything other than an attribute lookup?

Example: The following fails with a Antlr4.StringTemplate.Compiler.TemplateException.

Template template = new Template("{AAA04EC0-301F-11D3-BF1B-00C04F79AAAC}", '{', '}');
1

There are 1 best solutions below

1
On

Yes and no.

Yes: The StringTemplate group syntax was updated to allow - characters to appear as part of an attribute name (but not as the first character). I'm not sure the template lexer was update to allow you to actually use such an attribute. You should file an issue on the issue tracker for the project: https://github.com/antlr/stringtemplate4/issues

No: An attribute name cannot start with a digit, so only GUID values starting with a letter would work.