[squeak-dev] Converting underscore assignment to ANSI?
Casey Ransberger
casey.obrien.r at gmail.com
Fri May 13 23:13:21 UTC 2011
Levente, I will try your script when I get close to shipping:) Thank you so
much! I think I may just add this one to my 'do...' menu, since I plan to be
hauling a bunch of code back and forth from Cuis and Squeak.
On Fri, May 13, 2011 at 4:07 PM, Levente Uzonyi <leves at elte.hu> wrote:
> On Fri, 13 May 2011, Casey Ransberger wrote:
>
> Hello everyone,
>>
>> I have some code I wrote for Cuis, where we prefer underscore (left arrow)
>> assignment, which I've had occasion to start porting to Squeak. Without
>> the
>> left-arrow glyph, the underscores look really awful, and I'd like to be
>> able
>> to swap them for ANSI assignment if I release the code for platforms other
>> than Cuis. I've googled a bit and searched the projects on SqueakSource,
>> but
>> I'm not finding FixUnderscores.
>>
>> Also, I was wondering if FixUnderscores had any gotchas I might want to
>> worry about.
>>
>
> As I wrote it recently, FixUnderscores is crap. FixUnderscores2 is a lot
> better (properly fixes underscores, doesn't modify your fonts, etc).
> But it's pretty easy to write such code in Squeak without subclassing
> Scanner, so I hacked together the following (evaluate it in a workspace):
>
> fixUnderScoresInSourceString := [ :methodString |
> String streamContents: [ :stream |
> | previousUnderscoreIndex |
> previousUnderscoreIndex := 0.
> Scanner new
> scanTokenPositionsIn: methodString
> into: [ :startPosition :endPosition |
> (startPosition = endPosition and: [
> (methodString at: startPosition) ==
> $_ ]) ifTrue: [
> stream
> next: startPosition
> - previousUnderscoreIndex - 1
> putAll: methodString
> startingAt:
> previousUnderscoreIndex + 1;
> nextPutAll: ':='.
> previousUnderscoreIndex :=
> startPosition ] ].
> stream
> next: methodString size - previousUnderscoreIndex
> putAll: methodString
> startingAt: previousUnderscoreIndex + 1 ] ].
>
> fixUnderScoresInMethod := [ :compiledMethod |
> | source fixedSource |
> source := compiledMethod getSource asString.
> fixedSource := fixUnderScoresInSourceString value: source.
> source = fixedSource
> ifTrue: [ false ]
> ifFalse: [
> compiledMethod methodClass
> compile: fixedSource
> classified: (compiledMethod methodClass
> organization categoryOfElement: compiledMethod selector)
> withStamp: compiledMethod timeStamp
> notifying: nil.
> true ] ].
>
> testMethodString := 'testMethod
> "This_is_a_comment_with_underscores."
>
> | x |
> x _ $_.
> ^x = ''_'' first and: [ x = #''_'' first and: [ x = #(_) first first
> ] ]'.
>
> underscoresTest := Object subclass: #UnderscoresTest
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'UnderscoresTest'.
>
> underscoresTest compile: testMethodString classified: 'instance side
> method'.
> underscoresTest class compile: testMethodString classified: 'class side
> method'.
> Object compile: testMethodString classified: '*UnderscoresTest'.
>
> CurrentReadOnlySourceFiles cacheDuring: [
> ((PackageInfo named: 'UnderscoresTest') methods select: [ :each |
> fixUnderScoresInMethod value: each compiledMethod ]) explore
> ]
> "add your assertions here :)"
>
>
> Levente
>
>
>
>> Thanks in advance for any pointers you can give!
>>
>> --
>> Casey Ransberger
>>
>>
>
--
Casey Ransberger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20110513/787b5b34/attachment.htm
More information about the Squeak-dev
mailing list
|