[squeak-dev] Reusable browsers was Re: About HyperCard
Bob Arning
arning315 at comcast.net
Sat Mar 2 17:10:19 UTC 2013
On 3/2/13 7:48 AM, Bert Freudenberg wrote:
> 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?:)
Maybe this will do:
'From Squeak4.4 of 1 March 2013 [latest update: #12489] on 2 March 2013
at 12:08:27 pm'!
"Change Set: FindSelector2
Date: 2 March 2013
Author: Bob Arning
String>>findSelector2 uses Scanner to better ignore extraneous stuff"!
!Scanner methodsFor: 'expression types' stamp: 'raa 3/2/2013 11:55'!
scanForFindSelectorUpTo: terminator
"
Scanner findSelectorTests
"
| s |
s := WriteStream on: (String new: 100).
[tokenType == terminator or: [tokenType == #doIt]] whileFalse: [
tokenType caseOf: {
[#leftParenthesis] -> [self scanToken;
scanForFindSelectorUpTo: #rightParenthesis].
[#leftBracket] -> [self scanToken; scanForFindSelectorUpTo:
#rightBracket].
[#leftBrace] -> [self scanToken; scanForFindSelectorUpTo:
#rightBrace].
[#keyword] -> [s nextPutAll: token].
} otherwise: [].
self scanToken
].
^s contents! !
!Scanner class methodsFor: 'testing' stamp: 'raa 3/2/2013 12:05'!
findSelectorIn: aString
| result |
result _ Scanner new
scan: (ReadStream on: aString);
scanForFindSelectorUpTo: #notATerminator.
^result! !
!Scanner class methodsFor: 'testing' stamp: 'raa 3/2/2013 12:02'!
findSelectorTests
"
Scanner findSelectorTests explore
"
^#(
'3 perform: #between:and: with: 1 with: 5'
'self do: [:i | ] separatedBy: [] '
'self perform: #add: with: anObject'
'self do: [:i | i do: [ :each | ] ] separatedBy: [] '
'self x: {self y:} y: ''self new: 100'''
'a max:b'
'a'
) collect: [ :e |
{e. self findSelectorIn: e}
].! !
!String methodsFor: 'converting' stamp: 'raa 3/2/2013 12:02'!
findSelector2
"Revised to use scanner for better removal of extraneous stuff"
| sel |
sel := self withBlanksTrimmed.
(sel includes: $:) ifTrue: [sel _ Scanner findSelectorIn: sel].
sel isEmpty ifTrue: [^ nil].
sel isOctetString ifTrue: [sel := sel asOctetString].
Symbol hasInterned: sel ifTrue:
[:aSymbol | ^ aSymbol].
^ nil! !
More information about the Squeak-dev
mailing list
|