[stringtemplate-interest] new "null" option for ST expressions
Terence Parr
parrt at cs.usfca.edu
Thu Jul 20 13:12:46 PDT 2006
hi. There is an inefficiency when dealing with big sparse lists of
ints; creating new Integer objects with, say, -1 to fill the other
spots is super wasteful and slow (otherwise no value shows up--ST
skips it). With ANTLR codegen, it takes 20% extra on entire exec
time to do this.
This led me to a null option:
o Added null=expr option on expressions.
For null values in iterated attributes and single attributes that are
null, use this value instead of skipping. For single valued
attributes like <name; null="n/a">
It's a shorthand for
<if(name)><name><else>n/a<endif>
For iterated values
<values; null="0", separator=",">
you get 0 for or null list values. Works for template application
like this also:
<values:{v| <v>}; null="0">
BUT! This forced me to make a more clear distinction between empty
and null:
o BACKWARD INCOMPATIBLE: I had to make a more clear distinction
between empty and null. Null means there is nothing there whereas
empty means the value is there but renders to an empty string. IF
conditionals now evaluate to empty if condition is false.
THIS led me to:
o BACKWARD INCOMPATIBLE: Changed how separators are generated. Now I
generate a separator for any non-null value in the list even if that
value is a conditional that evaluates to false. Iterated empty values
always get a separator. Note that empty is not the same thing as
missing. "" is not missing and hence will get a separator.
This made the ASTExpr.write separator computation much simpler and
allowed me to properly handle the new "null" option.
This actually didn't break anything but I had to alter a unit test to
a different meaning.
Pushed in depot.
Ter
More information about the stringtemplate-interest
mailing list