The Trunk: Collections-ct.1115.mcz
| Newsgroups | gmane.comp.lang.smalltalk.squeak.general |
|---|---|
| Message-ID | <[email protected]> |
Christoph Thiede uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ct.1115.mcz
==================== Summary ====================
Name: Collections-ct.1115
Author: ct
Time: 6 June 2026, 4:22:42.019702 pm
UUID: d51cc77e-82cc-4729-b29a-ff7b66b0689c
Ancestors: Collections-ct.1114
Fixes escaping slip in #findSelector for symbols before closing parentheses/brackets/braces.
E.g. 'collect: (#foo) thenSelect:' findSelector
Eliot's code ('collect: (#foo) thenSelect: #(bar)' findSelector) does not have this problem. :-)
=============== Diff against Collections-ct.1114 ===============
Item was changed:
----- Method: String>>findSelector (in category 'converting') -----
findSelector
"Attempt to find the rightmost selector within the receiver which is expected to be some fragmentary Smalltalk expression."
| sel possibleParens |
sel := self withBlanksTrimmed.
self flag: #refactor. "ct: It would be nice if we could use just the parser for finding the rightmost selector... See #testFindSelector. Dan's code doesn't need this first regex."
sel := sel copyWithRegex: '^((?:\S(?<!!\:))+\s+)+' matchesReplacedWith: ''. "strip leading receivers"
"Eliot's code using the facilities..."
([Parser new parseMessage: sel]
on: UnknownSymbolNotification
do: [])
ifNotNil: [:selector| ^selector].
"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 includes: $:)
ifTrue:
[sel := sel copyWithRegex: '''[^'']*''' matchesReplacedWith: '''a string'''.
+ sel := sel copyWithRegex: '#[^\[\(\)\}\]\s\.$]*' matchesReplacedWith: '#aSymbol'.
- sel := sel copyWithRegex: '#[^\[\(\s\.$]*' matchesReplacedWith: '#aSymbol'.
sel := sel copyWithRegex: '\$.' matchesReplacedWith: '$x'. "handle $( $[ and $:"
sel := sel copyWithRegex: '\:(?!!=)' matchesReplacedWith: ': '. "for the style (aa max:bb) with no space"
sel := sel copyReplaceAll: '[:' with: '[ :'. "for the style ([:a) with no space"
possibleParens := sel substrings.
sel := self class streamContents:
[:s | | level |
level := 0.
possibleParens do:
[:token |
(level = 0 and: [token endsWith: ':'])
ifTrue: [s nextPutAll: token]
ifFalse: [level := level
+ (token occurrencesOf: $() - (token occurrencesOf: $))
+ (token occurrencesOf: $[) - (token occurrencesOf: $])
+ (token occurrencesOf: ${) - (token occurrencesOf: $})]]]]
ifFalse:
[sel := self substrings ifNotEmpty: [:tokens | tokens last]].
sel ifEmpty: [^ nil].
sel first = $# ifTrue:
[sel := sel allButFirst.
sel ifEmpty: [^ nil]].
sel isOctetString ifTrue: [sel := sel asOctetString].
^ Symbol lookup: sel!
Squeak-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]