[stringtemplate-interest] ST4: Early evaluation of default arguments
Sam Harwell
sharwell at pixelminegames.com
Tue May 10 09:15:50 PDT 2011
Hi Ter,
I resolved this in the C# port by completely getting rid of
Interpreter.current_ip and making it a local variable of the current frame.
This may differ from the behavior of the Java version because I don't keep a
copy of the current frame as an instance variable in the interpreter - I
always pass it as a parameter to the various methods.
Sam
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Udo
Borkowski
Sent: Tuesday, May 10, 2011 10:40 AM
To: Terence Parr
Cc: stringtemplate-interest Template
Subject: Re: [stringtemplate-interest] ST4: Early evaluation of default
arguments
perhaps {<({...})>} works? ;)
Yes and no.
E.g. the following group:
main() ::= <<
<f(p="x")>*<f(p="y")>
>>
f(p,q={<({a<p>})>}) ::= <<
-<q>-
>>
renders nicely to the expected result "-ax-*-ay-".
However calling st.inspect() instead of st.render() runs into an exception,
even before the Inspect window opens:
java.lang.ArrayIndexOutOfBoundsException: 24
at
org.stringtemplate.v4.misc.STRuntimeMessage.getSourceLocation(STRuntimeMessa
ge.java:72)
at
org.stringtemplate.v4.misc.STRuntimeMessage.toString(STRuntimeMessage.java:8
3)
at
javax.swing.DefaultListCellRenderer.getListCellRendererComponent(DefaultList
CellRenderer.java:134)
at
javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1344)
...
at java.awt.Window.pack(Window.java:706)
at org.stringtemplate.v4.gui.STViz.open(STViz.java:212)
at org.stringtemplate.v4.ST.inspect(ST.java:471)
at org.stringtemplate.v4.ST.inspect(ST.java:454)
at org.stringtemplate.v4.ST.inspect(ST.java:447)
at
org.stringtemplate.v4.debug.InspectTest.testEarlyEval(InspectTest.java:92)
...
I tried to debug this, but with no success. However I noticed including
"<f(...)>" only once will render correctly and also the inspect works.
I submitted my test case (TestEarlyEvaluation) into the Perforce repository.
Udo
On 04.05.2011, at 02:02, Terence Parr wrote:
perhaps {<({...})>} works? ;)
Ter
On Apr 30, 2011, at 3:39 AM, Udo Borkowski wrote:
Currently the only way to enforce early evaluation of template default
arguments is through the syntax:
I.e. one can only early evaluate anonymous template that contain just an
expression tag.
It would be nice to also support early evaluation on any kind of anonymous
template.
E.g. in
http://www.antlr.org/pipermail/stringtemplate-interest/2009-August/002097.ht
ml Ter gave the following example:
However this will not give the expected result in ST4 (early evaluation of
"end<(uniq)>").
Maybe we could extend the syntax for default arguments to also support
p = ({ ... })
i.e. putting "( . )" around the template forces early evaluation?
What do others think?
Udo
_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org
http://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110510/8d976d9e/attachment-0001.html
More information about the stringtemplate-interest
mailing list