Hi there,<br><br>I've had a look at that function on the STG but my problem exists when iterating through the ST's chunks. Each chunk object has no clear 'Name' method from what I can see therefore I cannot pass getMap() the name of the map.<br>
<br>I see you mentioned a 'Map' object on the getMap() STG return type. The version of assembly I'm using does not seem to have this object.<br><br>Below is a sample of my code to give more context around the question:<br>
<br><br><u><b>Assemblies: </b></u><br>antlr.runtime.dll - V 2.7.7.3<br>StringTemplate.dll - V 3.0.1.6846<br><br><u><b>Expected Output:</b></u> <br>My Dog barks. <br><br><br><u><b>C# code snippet:</b></u><br><br>Public void Process()<br>
{<br> Console.WriteLine(RenderTemplate(new Dictionary<string, object>(){"AnimalName","Dog"}));<br>}<br><br>public string RenderTemplate(Dictionary<string, object> parameters)<br>{<br> StringTemplateGroup group = new StringTemplateGroup("mygroup", "c:/temp/my.stg");<br>
<br> StringTemplate st = group.GetInstanceOf("test1");<br><br> foreach (object chunk in st.Chunks)<br> {<br> if (chunk != null)<br> {<br> if (chunk.GetType() == typeof(ASTExpr))<br>
{<br><span style="color: rgb(0, 153, 0);"> //</span><br style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 153, 0);"> // Insert code here to determine if chunk is a Map</span><br style="color: rgb(0, 153, 0);">
<span style="color: rgb(0, 153, 0);"> //</span><br> string mapName = ((ASTExpr)chunk)<b style="color: rgb(204, 0, 0);">.?????????? </b><br><span style="color: rgb(0, 153, 0);"> /*<br> 1. chunk.ToString returns "( . soundNameMap ( value AnimalName ) )"....Based on the sample Template below.<br>
I don't want to implement a dirty fix here to strip out the map name<br> <br> 2. (((StringTemplateAST)((ASTExpr)(chunk)).AST).getText() returns "."<br> <br>
3. (((StringTemplateAST)((ASTExpr)(chunk)).AST).Type returns int 24. I'm unable to determine what this value maps to? <br> I've searched on the StringTemplate documentation and can find no enumeration mapping.<br>
*/</span><br><br> <span style="color: rgb(0, 153, 0);">//I do not have a 'Map' object in the assembly version listed above.</span><br> IDictionary map = group.GetMap(mapName);<br>
<br> <span style="color: rgb(0, 153, 0);">//Don't do anything if the chunk is a map.</span><br> if(map == null)) <br> {<br> <span style="color: rgb(0, 153, 0);">// No map found thus, for this example, we assume it's a placeholder variable in the template</span><br>
if(parameters.ContainsKey(placeholder)<br> {<br> st.SetAttribute(chunk.ToString(), parameters[placeholder]);<br> }<br> else<br> {<br>
throw new ParameterNotFoundException("Parameter '" + chunk.ToString() + "' is not in Dictionary.");<br> }<br> }<br> }<br> }<br> }<br>
<br> return st.ToString();<br>}<br><br><u><b>STG Template - "my.stg"<br><br></b></u>group mygroup;<br><br>soundNameMap ::= [<br> "Dog": "barks",<br> "Cat": "meows",<br>
default: "N/A"<br>]<br><br>test1(AnimalName) ::= <<<br>My $AnimalName$ $soundNameMap.(AnimalName)$.<br>>><br><br><br><br><br><br><div class="gmail_quote">2009/8/19 Terence Parr <span dir="ltr"><<a href="mailto:parrt@cs.usfca.edu">parrt@cs.usfca.edu</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">see<br>
<br>
public Map getMap(String name) {}<br>
<br>
in STG. or subclass and walk field maps.<br>
T<div><div></div><div class="h5"><br>
<br>
On Aug 18, 2009, at 6:38 AM, Jacques Victor wrote:<br>
<br>
</div></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">
Hi there,<br>
<br>
I've recently started using StringTemplate and today have run into a brick wall...so to speak...<br>
<br>
I'm loading my *stg file in .Net (C#) and setting the stringtemplate placeholder variables via a Dictionary. Once determining a chunk is of type 'ASTExpr', I I'm struggling to determine if that chunk is indeed a map and therefore not checking against my Dictionary and throwing an error if I don't find the chunk placeholder variable in the Dictionary.<br>
<br>
Is it possible to get all the maps defined in a Stringtemplategroup file or alternatively as I iterate through the chunks, in the StringTemplate object, be able to identify a chunk as a map?<br>
<br>
I've searched the internet but can't find any enum/type that would make a map chunk distinguishable, from other chunks, in .Net.<br>
<br>
Any help would greatly be appreciated.<br>
<br>
Thanks in advance.<br>
<br>
Regards<br>
Jacques<br></div></div>
_______________________________________________<br>
stringtemplate-interest mailing list<br>
<a href="mailto:stringtemplate-interest@antlr.org" target="_blank">stringtemplate-interest@antlr.org</a><br>
<a href="http://www.antlr.org/mailman/listinfo/stringtemplate-interest" target="_blank">http://www.antlr.org/mailman/listinfo/stringtemplate-interest</a><br>
</blockquote>
<br>
</blockquote></div><br>