[stringtemplate-interest] need a null value for arguments?

Terence Parr parrt at cs.usfca.edu
Tue Aug 2 12:25:26 PDT 2011


On Aug 2, 2011, at 12:33 AM, Udo Borkowski wrote:

>> Adding “undefined” seems pointless, since you can already get that by simply omitting an argument.
> 
> There are at least two situations I can think of that require an "undefined" literal, i.e. omitting an argument is not an option in those cases:
> 
> 1. "Pass Thru"
> 
> Assume you have a template with many parameters and you are using pass thru ("…") to use the values from the caller. 
> 
> E.g.
> 
> caller(p1,p2,p3,p4,p5,p6,p7,p8,p9) ::= "      <t(…)>    "
> 
> t(p1,p2,p3,p4,p5,p6,p7,p8,p9="def9") ::= <<    <p9>    >>

Hi Udo. wouldn't null work here as well?

> 
> If you want to call t but ensure p9 uses its default value and not the "pass thru" value from the caller you would write:
> 
> 	<t(p9=undefined,…)>
> 
> Using null in this case would just omit the output for p9. 

Actually, null implies you get the default value. wait.  actually it doesn't work that way! crap!  Hmm...I we defined null as missing during iteration and so on. If that is true, then this is a bug in the semantics I should fix.

> 2. "Argument by position"
> 
> If you are calling templates in the new "argument by position" style (i.e. omitting the parameter name in the arguments) the "undefined" comes in handy to get an "undefined" parameter in "middle" of the argument list.
> 
> E.g. you got this template 
> 
> t(p1="def1",p2="def2",p3="def3",p4="def4",p5="def5",p6="def6",p7="def7",p8="def8",p9="def9") ::= <<  ...    >>
> 
> and call it:
> 
> 	<t("A",undefined,"C","D","E","F","G")>
> 
> Here p2 will get the value "def2".

Hmm...yeah, I think we might have an inconsistency here. Okay, looking back at my notes

http://www.antlr.org/wiki/display/ST4/Differences+between+v3+and+v4

i see the following:

	• missing vs empty; null in list and false-IF are like missing; empty is "" or <else><endif> clause
	• null values for attr allowed; st.add("name", null). same as missing.
it's added to list if we add other values afterwards. same
now as sending in list of null

So, it sounds like I simply need to make null work like missing in the case of default arguments. Thanks for catching this, Udo!


Ter



More information about the stringtemplate-interest mailing list