From: Eric B. R. <eb...@tc...> - 2003-05-13 05:34:41
|
<snip> > A built-in Map declaration syntax would help here. E.g., <snip> > Since I don't see this coming anytime soon, how about a $map function: Disclaimer: I only spent an hour and 15 minutes on this... I've just committed some highly experimental Map support into CVS. #set $map = { "key" => "value", "foo" => "bar" } $map.key $map.foo Along with all the variants such as a map of maps, an empty map (#set $foo = {}), and of course using $variables as keys and values. I haven't written test cases yet, but some quick-n-dirty standalone testing shows it works, PLUS all existing test cases still pass. woo hoo! We can tweak the syntax, but I *really* like having the curly braces around the map. Plus, I tried to make it work with square brackets but javacc got confused with lists, and I don't understand LOOKAHEAD yet. Right now it uses a java.util.HashMap as the backing store, but I'd like to somehow make this configurable via WebMacro.properties, so we can use any Map implementation. Maybe TreeMap or some custom CaseInsensitiveStringKeyMapThingie so $map.Key and $map.keY are the same thing. Who knows. But I think this is a good start. eric |