Hi there,<br><br>I&#39;ve had a look at that function on the STG but my problem exists when iterating through the ST&#39;s chunks. Each chunk object has no clear &#39;Name&#39; method from what I can see therefore I cannot pass getMap() the name of the map.<br>
<br>I see you mentioned a &#39;Map&#39; object on the getMap() STG return type. The version of assembly I&#39;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&lt;string, object&gt;(){&quot;AnimalName&quot;,&quot;Dog&quot;}));<br>}<br><br>public string RenderTemplate(Dictionary&lt;string, object&gt; parameters)<br>{<br>    StringTemplateGroup group = new StringTemplateGroup(&quot;mygroup&quot;, &quot;c:/temp/my.stg&quot;);<br>
<br>    StringTemplate st = group.GetInstanceOf(&quot;test1&quot;);<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 &quot;( . soundNameMap ( value AnimalName ) )&quot;....Based on the sample Template below.<br>
                    I don&#39;t want to implement a dirty fix here to strip out the map name<br>                <br>                2. (((StringTemplateAST)((ASTExpr)(chunk)).AST).getText() returns &quot;.&quot;<br>                <br>
                3. (((StringTemplateAST)((ASTExpr)(chunk)).AST).Type returns int 24. I&#39;m unable to determine what this value maps to? <br>                    I&#39;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 &#39;Map&#39; object in the assembly version listed above.</span><br>            IDictionary map = group.GetMap(mapName);<br>
            <br>            <span style="color: rgb(0, 153, 0);">//Don&#39;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&#39;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(&quot;Parameter &#39;&quot; + chunk.ToString() + &quot;&#39; is not in Dictionary.&quot;);<br>                }<br>            }<br>          }<br>        }<br>    }<br>
    <br>    return st.ToString();<br>}<br><br><u><b>STG Template - &quot;my.stg&quot;<br><br></b></u>group mygroup;<br><br>soundNameMap ::= [<br>   &quot;Dog&quot;:      &quot;barks&quot;,<br>   &quot;Cat&quot;: &quot;meows&quot;,<br>
    default:   &quot;N/A&quot;<br>]<br><br>test1(AnimalName) ::= &lt;&lt;<br>My $AnimalName$ $soundNameMap.(AnimalName)$.<br>&gt;&gt;<br><br><br><br><br><br><div class="gmail_quote">2009/8/19 Terence Parr <span dir="ltr">&lt;<a href="mailto:parrt@cs.usfca.edu">parrt@cs.usfca.edu</a>&gt;</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&#39;ve recently started using StringTemplate and today have run into a brick wall...so to speak...<br>
<br>
I&#39;m loading my *stg file in .Net (C#) and setting the stringtemplate placeholder variables via a Dictionary. Once determining a chunk is of type &#39;ASTExpr&#39;, I I&#39;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&#39;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&#39;ve searched the internet but can&#39;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>