antlr / antlrcs

The C# port of ANTLR 3, StringTemplate 3, and StringTemplate 4
Other
282 stars 81 forks source link

Create StringTemplate 4 examples / getting started documentation #15

Open sharwell opened 11 years ago

st4l commented 11 years ago

Sam, what's the lookup list for attribute properties? I'm having issues trying to render

var dict = Dictionary<string, MyType>;

Tried passing dict.Values to a template and it doesn't find any objects, passing dict renders the Keys collection.

st4l commented 11 years ago

More details.

table(relation) ::= <<
CREATE TABLE <relation.Name>
 <relation.Columns.Values:col()>
>>
col(col) ::= <<
   column <col.Name> 
>>

When I look at this in visualizer, I'm guessing it resolves relation.Columns first, which is the Dictionary<string,Column>, and it enumerates the Keys collection. When it tries to resolve .Values it doesn't find it because it has the enumeration results, not the actual object.

st4l commented 11 years ago

And... bingo Not intuitive, and hadn't found anything in the documentation about this:

       if (property == null)
                value = map[TemplateGroup.DefaultKey];
            else if (property.Equals("keys"))
                value = map.Keys;
            else if (property.Equals("values"))

(in Antlr4.StringTemplate\Misc\MapModelAdaptor.cs)

The adapter expects '.keys' or '.values' in lower-case. You could either change the capitalization there (to align it with c#/.NET conventions) or write a note in the documentation about the case for those properties. I tested it and it works for <rel.Columns.values:col()>