About the new compiler, Part I

Lukas Renggli renggli at gmail.com
Sun Jan 20 11:01:27 UTC 2008


> >> Since you have the transformations available, you could use them as
> >> macros to eliminate some of the cases here. For example, #ifNil: can
> >> be transformed into "isNil ifTrue:".
>
> Stephen Compall has been working on "message macros" for GNU Smalltalk
> with his Presource package, living at
> http://smalltalk.gnu.org/project/presource (Stephen is CCed).

I also wrote a macro system ;-)

In my case this for Squeak and in the context of improving the DSL
(domain specific language) capabilities of Smalltalk. A simple macro
transformation rule based on RB rules looks for example like this:

inlineBetweenAnd
	<rule: 100>
	
	^ OrderedCollection new
		add: (DSLMacroStringDefinition new
			search: '``@a between: ``@b and: ``@c';
			replace: '``@a >= ``@b and: [ ``@a <= ``@c ]';
			verification: [ :context :node |
				node receiver isImmediate
					and: [ node arguments allSatisfy: [ :each | each isImmediate ] ] ]);
		yourself

The transformations are not restricted to source-code transformation,
but can also be used to improve the editor. The example below uses a
mixture of an RB matcher and several regular expressions matcher. It
highlights XHTML tags within literal strings:

htmlTagsInString
	<rule: 100>
	
	^ DSLSearchPattern new
		expression: '`{ :node | node isLiteral and: [ node value isString ] }';
		action: (Array
			with: (DSLMatchPattern new
				expression: '</?(\w+)\s*([^>]*)>';
				action: Color blue asStyle;
				at: 2 action: TextEmphasis bold asStyle;
				at: 3 action: (DSLMatchPattern new
					expression: '(\w+)=("[^"]*")';
					at: 3 action: TextColor magenta asStyle))
			with: (DSLRangePattern new
				begin: '<!--'; end: '-->';
				outerAction: (Color r: 0 g: 0.5 b: 0) asStyle))

Cheers,
Lukas

-- 
Lukas Renggli
http://www.lukas-renggli.ch



More information about the Squeak-dev mailing list