[stringtemplate-interest] ST4: Early evaluation of default arguments

Udo Borkowski ub at abego-software.de
Tue May 10 08:39:37 PDT 2011


> 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(STRuntimeMessage.java:72)
	at org.stringtemplate.v4.misc.STRuntimeMessage.toString(STRuntimeMessage.java:83)
	at javax.swing.DefaultListCellRenderer.getListCellRendererComponent(DefaultListCellRenderer.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.html 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/9e87eac1/attachment.html 


More information about the stringtemplate-interest mailing list