Hello, I have some trouble in understanding how scopes can be used during the transform.
I am trying to implement a stringtemplate <http://www.antlr.org/wiki/display/ST4/StringTemplate+cheat+sheet> interpreter. The parser parts works like a charm, but I am struggling with the transformation. In stringtemplate, there is something called anonymous templates that work in a similar fashion to the Array.map function in ruby. For example, the following stringtemplate code loops through "bar" values, assign each value to "item" in the {} context and display its value. === $bar:{ item | $item$ }$ === equivalent ruby code: === bar.map{ |item| p item } === Using the following input string: ===== $foo$ $bar:{ item | $item$ }$ ===== My parser is generating the following tree: ===== {:template_code=> [{:expression=> [{:variable=>{:template_variable=>{:variable_atom=>"foo"@1}}}]}, {:expression=> [{:anonymous_template=> {:variable=>{:template_variable=>{:variable_atom=>"bar"@16}}, :anonymous_variable=>"item"@22, :template_code=> [{:expression=> [{:variable=> {:template_variable=>{:variable_atom=>"item"@30}}}]}]}}]}]} ===== I noticed the transform will process the value "bar" before "item". But I am stuck on how to access the value of "bar" when processing "item" value, or in a more generic way in how to set/access scopes during transform. What would be a good solution to this problem? The current code of the parser and transform can be checked here < http://pastebin.com/3UB675f4 >. Any help will be greatly appreciated, Thanks in advance! Cheers, -- Eric Sagnes サニエ エリック
signature.asc
Description: This is a digitally signed message part.
