[squeak-dev] String>expandMacros rules?

John Brant brant at refactoryworkers.com
Mon Mar 6 14:21:58 UTC 2017


On 03/05/2017 02:23 PM, tim Rowledge wrote:
> Whilst looking for ways of formatting values of my weather data I discovered the String>expandMacros etc methods, which look rather like they are intended to do something like formatting. But there are no comments, no hints about what is supposed to happen, etc, etc. Couldn’t find anything in the swiki either. None of it appears to be used except in a single unit test.
>
> So what is meant to happen here?

I'm guessing that these methods originally came from the Refactoring 
Browser port. VisualWorks has expandMacros* methods which were used by 
the RB. When the RB was ported, these were created to support the parts 
of expandMacros that the RB used. I don't know if the VW expandMacros 
supports more features.

Here are the rules:

*) All text is output directly
*) Special items are delimited by <>
*) <n> inserts a cr
*) <t> inserts a tab
*) <#p> prints the # argument on the stream
*) <#s> appends the # argument on the stream (for strings)
*) <#?trueValue:falseValue> if # argument is true output trueValue else 
output falseValue (good luck if you want a colon in your true value or a 
greater than in either part)
*) If you want a < character in your string, you need %< (I don't 
remember if the original RB implementation had this, but it appears that 
Squeak now does)

Here's an example, that shows all features:

'%<<1p><n><t>Apple<2?s:><n><3s>'
	expandMacrosWith: 1
	with: #() size ~= 1
	with: 'This is a string'
=>
'<1
	Apples
This is a string'

As a macro expansion goes, it isn't that powerful, but it is fairly simple.


John Brant


More information about the Squeak-dev mailing list