[stringtemplate-interest] ST map improvement
Terence Parr
parrt at cs.usfca.edu
Sat Jan 7 10:41:31 PST 2006
On Jan 4, 2006, at 6:57 AM, Andrew Goodnough wrote:
> In this case a default of "UNSUPPORTED_OPERATION" is fine but there
> are other cases where I want the default to just return the key
> value. So if it's not in the map, just give me the original value
> back. Something like:
>
> opMap ::= [
> "ADD":"ADD",
> "CHANGE":"MODIFY",
> "REMOVE":"DROP",
> default:key
> ]
Interesting...what if no default meant you get the key? Actually we
need this to be consistent with a new syntax for map
iteration...currently it's a braindead iterate-over-values thing:
<symbols:{s|<s.type> <s.name>}>
what if it's just text to text though? You really want the keys so
you can do this with the indirect field accessor:
<aMap:{key|<key> maps to <aMap.(key)>}
Actually, the key is not a "keyword" so no need to make consistent.
> or maybe even better:
>
> opMap ::= [
> "ADD":"ADD",
> "CHANGE":"MODIFY",
> "REMOVE":"DROP",
> default:<op_key()> //where op_key() is a defined template
> ]
I like this direction. Why not map string to arbitrary template
(string or template name) in general? Great idea!
> This would make the calling code more readable and concise.
> Instead of:
>
> <if(it.operation)><opMap.(it.operation)><else><it.operation><endif>
>
> it could be:
>
> <opMap.(it.operation)>
Useful.
> Would this be helpful for anyone else?
An excellent use-case for this option. What if you want default to
go to nothing? I.e., only spit something out if it's in a
vocabulary? Do I have a null or something? Can't remember!
Ter
More information about the stringtemplate-interest
mailing list