antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
955 stars 231 forks source link

Unable to use square brackets as delimiters #183

Closed Jericho closed 6 years ago

Jericho commented 7 years ago

Using StringTemplate4 nuget package version 4.0.8 in Visual Studio 2015.

The following C# code:

var st = new Template("Dear [firstname]", '[', ']');
st.Add("firstname", "Bob");
var result = st.Render();

Yields the following exception: Exception of type 'Antlr4.StringTemplate.Compiler.TemplateException' was thrown. with the following stack trace:

at Antlr4.StringTemplate.Compiler.TemplateCompiler.ReportMessageAndThrowTemplateException(ITokenStream tokens, IToken templateToken, Parser parser, RecognitionException re)
at Antlr4.StringTemplate.Compiler.TemplateCompiler.Compile(String srcName, String name, List`1 args, String template, IToken templateToken)
at Antlr4.StringTemplate.Template..ctor(TemplateGroup group, String template)

I had a discussion with Sam Harwell in the antlrcs gitter room and he pointed out that the issue is with the closing square bracket.

ncharles commented 7 years ago

This looks a lot like https://github.com/antlr/stringtemplate4/issues/172

parrt commented 6 years ago

We added a warning for those delimiters. https://github.com/antlr/stringtemplate4/pull/149

Jericho commented 6 years ago

@parrt I looked at the PR that you referenced and, as far as I can see, only @, - and _ (in addition to the letters of the alphabet and digits) are marked as "reserved". It doesn't seem to address the issue I reported with square brackets.

parrt commented 6 years ago

Ah. I better add those. thanks.