[squeak-dev] One liner challenge

Göran Krampe goran at krampe.se
Fri Mar 12 10:13:00 UTC 2010



Travis Griggs wrote:
> I don't think it's cheating at all. The whole point of such a post is to 
> see what techniques AND tools others use out of the box to solve 
> problems.  And you showed a cool one. One that I wasn't that aware of. 
> I'm curious what other ways you use your MacroProcessor for now. I 
> looked at the link, but the example didn't stir my imagination that much.

I wrote it initially in order to do ASP-ish templating. Then I ended up 
making it support #deep: (tries to expand the expansions in turn) and 
#recursive: (if macros inside macros should be expanded before the macro 
itself is expanded). And btw, it is a single class and doesn't do more 
than it says it does :)

I have used it both for web page templates and email templates.

Btw, here is most of the class comment:

"MacroProcessor is a preprocessor that can process a String and given a 
startString and an endString it will call a given model (or a pluggable 
block) to expand the contents found between those markers. The content 
between one such pair of start/end markers is called a macro. The result 
returned from the model/block is called an expansion.

MacroProcessor can either do one level expansion (not further expanding 
macros possibly produced by the expansions) or do deep expansion which 
means it will immediately try to further process produced expansions. It 
can also be configured to not recurse, which means it will not process 
the macro itself before expanding it. If recursing it will do left to 
right, inner first expansion."

regards, Göran

More information about the Squeak-dev mailing list