[squeak-dev] Reusable browsers was Re: About HyperCard
Bert Freudenberg
bert at freudenbergs.de
Sat Mar 2 12:48:25 UTC 2013
On 2013-03-02, at 02:57, "Juan Vuletich (mail lists)" <juanlists at jvuletich.org> wrote:
> Quoting Chris Muller <asqueaker at gmail.com>:
>
>>> Try this:
>>>
>>> self do: [:i | ] separatedBy: []
>>
>> Ha, ok, well, score +1 again for formatting code with more spacing in
>> it (total score: 3-1). ;-) I never noticed "block args" having the
>> problem since I always use more spacing (and, I guess, the code in the
>> system I've ever traced).
>>
>> So the real issue appears to be related to when a colon follows a
>> non-whitespace character, as it does in your example and in
>> keyword-selector symbol case:
>>
>> self perform: #add: with: anObject
>>
>> I just saw Bobs msg did half the work finding the method.. Hmm..
>
> This could be fixed with:
>
> findSelector
> "Dan's code for hunting down selectors with keyword parts; while this doesn't give a true parse, in most cases it does what we want, in where it doesn't, we're none the worse for it."
> | sel possibleParens level n keywordPos foundFirstKeyword |
> sel _ self withBlanksTrimmed.
> (sel includes: $:) ifTrue: [
> sel _ sel copyReplaceAll: ':' with: ': '. "for the style (aa max:bb) with no space"
> sel _ sel copyReplaceAll: '[:' with: '[ :'. "for the style ([:a) with no space"
> possibleParens _ sel findTokens: Character separators.
> sel _ String streamContents: [ :s |
> level _ 0.
> foundFirstKeyword _ false.
> keywordPos _ false.
> possibleParens do: [ :token |
> foundFirstKeyword
> ifFalse: [ token last = $: ifTrue: [ foundFirstKeyword _ keywordPos _ true ]]
> ifTrue: [ keywordPos _ keywordPos not ].
> (level = 0 and: [ keywordPos ])
> ifTrue: [s nextPutAll: token]
> ifFalse: [(n _ token occurrencesOf: $( ) > 0 ifTrue: [level _ level + n].
> (n _ token occurrencesOf: $[ ) > 0 ifTrue: [level _ level + n].
> (n _ token occurrencesOf: $] ) > 0 ifTrue: [level _ level - n].
> (n _ token occurrencesOf: $) ) > 0 ifTrue: [level _ level - n]]]]].
>
> sel isEmpty ifTrue: [^ nil].
> Symbol hasInterned: sel ifTrue: [ :aSymbol |
> ^ aSymbol].
> ^ nil
Not quite:
'3 perform: #between:and: with: 1 with: 5' findSelector
==> nil
I just pushed a version to trunk that has Bob's "[:" improvement, and I added "{}" handling.
The proper way to deal with the remaining cases (short of actual parsing) would be to strip all Strings/Symbols/Comments before the tokenization, I think. Takers? :)
- Bert -
More information about the Squeak-dev
mailing list
|