[squeak-dev] Re: Can i has underscores? :)

Andreas Raab andreas.raab at gmx.de
Thu Apr 15 04:39:20 UTC 2010


On 4/14/2010 5:22 PM, Igor Stasenko wrote:
> Here the code, Stéphane.
>
> Please, let me know, if it meets your expectations.

Ah! See *now* we're talking. This is useful because we can immediately 
put this to a real test along the lines of:

Smalltalk allClasses do:[:cls|
   cls selectorsAndMethodsDo:[:sel :method|
     | source filtered node compiled |
     source := (cls sourceCodeAt: sel) asString.
     (source indexOf: $_) > 0 ifTrue:[
       filtered := (UnderscoreFilter on: source readStream)
         replacement: ':='; upToEnd.
       source = filtered ifFalse:[
         Transcript cr; show: cls name, '>>', sel.
         node := cls compilerClass new compile: filtered
           in: cls classified: nil notifying: nil ifFail: nil..
         compiled := node generate: method trailer.
         self assert: (method equivalentTo: compiled).
       ].
     ].
   ].
] displayingProgress:[:cls| 'Verifying ', cls name].

What this does is verifying that your underscore filter indeed replaces 
all the source code correctly. It also spits out where underscores are 
used and I was positively surprised that it seems as if there are 
precisely 11 methods with underscore assignments left in Squeak 4.1.

The other thing we can do with it is to wrap it into a more useful form 
where we 'auto-detect' whether to translate underscores and do so only 
if needed. Check out the attached code - it provides the fileIn 
facilities in a separate class so that we can properly modify and 
install variations by subclassing. Also note that the idea is that 
generally we detect the underscore usage by looking at the fileOut 
version (which is fast) but if not present we might look at the file 
contents, too (this is left as an exercise for the interested reader :-)

BTW, I've also added a test for a fileIn translation that shows a case 
where your filter goes wrong - when having something like #(1 2 3 _ 4 5) 
you're replacing the underscore in the literal array with := even though 
it's equivalent to #'_'.

Between UnderscoreFilter and FileInManager we're slowly getting there. 
The issues left are:
* Dealing with is Monticello. If we can figure out how to extract a 
SystemVersion string from it we should be able to use the same basic 
approach.
* Using the Unicode glyph. I'm not certain what the best way to deal 
with this is, but it'd be good if we could also support the 'real' 
left-arrow glyph and translate underscore to left-arrow instead of :=.
* Typing the Unicode glyph. This could be done by a simple preference 
that maps underscore to left-arrow.

Cheers,
   - Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: System-FileIn.st
Type: application/x-st
Size: 15278 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20100414/faa83b90/System-FileIn.bin


More information about the Squeak-dev mailing list