Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.891.mcz ==================== Summary ==================== Name: Collections-nice.891 Author: nice Time: 9 May 2020, 6:27:51.164977 pm UUID: 4b4cd1ee-3b62-4ee2-b819-5b4481f6ecee Ancestors: Collections-nice.890 Find a selector in a line containing an assignment This uses new (negative) lookahead extensions to Regex (hence requires Regex >= Regex-Core-ct.56). Example: try alt+m in following line (extracted from these changes): sel := sel copyReplaceAll: ':(?!=)' with: ': '. "blah" =============== Diff against Collections-nice.890 =============== Item was changed: ----- Method: String>>findSelector (in category 'converting') ----- 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 | sel := self withBlanksTrimmed. (sel includes: $:) ifTrue: [sel := sel copyWithRegex: '''[^'']*''' matchesReplacedWith: '''a string'''. sel := sel copyWithRegex: '#[^\[\(\s\.$]*' matchesReplacedWith: '#aSymbol'. sel := sel copyWithRegex: '\$.' matchesReplacedWith: '$x'. "handle $( $[ and $:" + sel := sel copyReplaceAll: ':(?!!=)' with: ': '. "for the style (aa max:bb) with no space" - 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 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! |
Hi Nicolas,
Does this work for you? #copyReplaceAll:with: appears not to accept regexes. For example, consider this output: '123' copyReplaceAll: '\d' with: 'x'. "'123'"
On my machine, the following does not work:
I selected everything and pressed <cmd>m. I would rather expect to be notified that there are not implementors of #foo:?
(By the way, see also the discussion in this thread. #copyReplaceAll:with: and #copyWithRegex:matchesReplacedWith: is another pair of similar-featured methods that maybe could be merged if we created a common protocol for comparison and matching ...)
Best, Christoph Von: Squeak-dev <[hidden email]> im Auftrag von [hidden email] <[hidden email]>
Gesendet: Samstag, 9. Mai 2020 18:27:53 An: [hidden email]; [hidden email] Betreff: [squeak-dev] The Trunk: Collections-nice.891.mcz Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.891.mcz ==================== Summary ==================== Name: Collections-nice.891 Author: nice Time: 9 May 2020, 6:27:51.164977 pm UUID: 4b4cd1ee-3b62-4ee2-b819-5b4481f6ecee Ancestors: Collections-nice.890 Find a selector in a line containing an assignment This uses new (negative) lookahead extensions to Regex (hence requires Regex >= Regex-Core-ct.56). Example: try alt+m in following line (extracted from these changes): sel := sel copyReplaceAll: ':(?!=)' with: ': '. "blah" =============== Diff against Collections-nice.890 =============== Item was changed: ----- Method: String>>findSelector (in category 'converting') ----- 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 | sel := self withBlanksTrimmed. (sel includes: $:) ifTrue: [sel := sel copyWithRegex: '''[^'']*''' matchesReplacedWith: '''a string'''. sel := sel copyWithRegex: '#[^\[\(\s\.$]*' matchesReplacedWith: '#aSymbol'. sel := sel copyWithRegex: '\$.' matchesReplacedWith: '$x'. "handle $( $[ and $:" + sel := sel copyReplaceAll: ':(?!!=)' with: ': '. "for the style (aa max:bb) with no space" - 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 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!
Carpe Squeak!
|
Le dim. 10 mai 2020 à 13:22, Thiede, Christoph <[hidden email]> a écrit :
Ouch! obviously, this was a low quality commit...
|
Free forum by Nabble | Edit this page |