[stringtemplate-interest] ST map improvement
Andrew Goodnough
Andrew.Goodnough at wicourts.gov
Tue Jan 10 08:14:55 PST 2006
I like your idea that no default section means a pass-through (which
just returns the original key). Thanks for taking a look. I wish I
could say that I'd try to implement this for you but I'm not familiar
enough with the code. Maybe it would be light work for you, though. :)
I'll take a look when I get time to see what I can come up with.
Andy
>>> Terence Parr <parrt at cs.usfca.edu> 01/07/06 12:41 pm >>>
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
_______________________________________________
stringtemplate- interest mailing list
stringtemplate- interest at antlr.org
http://www.antlr.org:8080/mailman/listinfo/stringtemplate- interest
More information about the stringtemplate-interest
mailing list