Porting from other dialects
John Brant
brant at cs.uiuc.edu
Wed Aug 19 01:54:19 UTC 1998
At 02:04 PM 8/18/98 -0600, Eugene Wallingford wrote:
>
>>This is one of the uses of the Refactoring Browser. It has a
>>pattern matcher that you can use to rewrite code. It is pretty
>>good at making large-scale changes to your system. Of course,
>>it doesn't work for Squeak yet.
>
> Maybe we should use the Refactoring Browser to port it. :-)
That's what I did when I ported it from VW to VA. It is relatively
easy to get the parser to work. Once it is working, then you can
write code to use the patten matcher directly (without going
through the Smalllint/Rewrite rule editor UI).
I've attached the changes needed to get the parser to work. It
parses almost every method in the system. The only exceptions
are 15 methods that use the {} construct, 1 method that has #_
as a symbol instead of #'_', 1 method that has #(:) instead of #($:),
3 methods with unnecessary periods before the first statement,
and 1 method with "- 1" instead of "-1" (no space).
To get the parser to work, you first need to install the block
temporary parser fix that has been posted before. Then you can
file-in the parser from the browser (you should get the latest
version from the archive). Finally, file-in my fixes below.
To use the pattern matcher you can execute something like:
| rewriter parseTree |
rewriter := ParseTreeRewriter new.
rewriter
replace: '``@object == nil' with: '``@object isNil';
replace: '``@object ~~ nil' with: '``@object notNil'.
Model withAllSubclasses do: [:each |
each selectors do: [:sel |
parseTree := each parseTreeFor: sel.
(parseTree notNil and: [rewriter executeTree: parseTree])
ifTrue: [Transcript
show: 'Need to compile:';
cr;
show: rewriter tree formattedCode;
cr]]]
If you want to learn what is available in the replace:with:
expressions, you can look at the rewrite tool documentation
off the Refactoring Browser page
http://st-www.cs.uiuc.edu/~brant/RefactoringBrowser
John Brant
---------------------
!Object methodsFor: 'testing' stamp: 'jmb 2/3/98 16:20'!
isBehavior
^false! !
!Object methodsFor: 'testing' stamp: 'jmb 2/3/98 16:40'!
isString
^false! !
!Object methodsFor: 'testing' stamp: 'jmb 2/3/98 16:40'!
isSymbol
^false! !
!Behavior methodsFor: 'testing' stamp: 'jmb 2/3/98 16:20'!
isBehavior
^true! !
!String methodsFor: 'testing' stamp: 'jmb 2/3/98 16:41'!
isString
^true! !
!Symbol methodsFor: 'testing' stamp: 'jmb 2/3/98 16:41'!
isSymbol
^true! !
!BRParser methodsFor: 'initialize-release' stamp: 'jmb 8/18/1998 16:30'!
initializeForSqueak
emptyStatements := true.
scanner notNil ifTrue: [scanner initializeForSqueak]! !
!BRParser methodsFor: 'initialize-release' stamp: 'jmb 8/18/1998 16:29'!
scanner: aScanner
scanner := aScanner.
tags := nil.
self initializeForSqueak.
self step! !
!BRScanner methodsFor: 'initialize-release' stamp: 'jmb 8/18/1998 16:31'!
initializeForSqueak
numberType := #scanNumberIBM.
separatorsInLiterals := true.
extendedLiterals := false! !
!BRScanner methodsFor: 'private-scanning' stamp: 'jmb 8/18/1998 15:26'!
scanSpecialCharacter
| character |
currentCharacter == $_ ifTrue:
[self step.
^BRAssignmentToken start: tokenStart].
currentCharacter == $: ifTrue:
[self step.
^currentCharacter == $=
ifTrue:
[self step.
BRAssignmentToken start: tokenStart]
ifFalse: [BRSpecialCharacterToken value: $: start: tokenStart]].
character := currentCharacter.
self step.
^BRSpecialCharacterToken value: character start: tokenStart! !
!BRScanner class methodsFor: 'class initialization' stamp: 'jmb 8/18/1998 15:26'!
initialize
MetaVariableCharacter := $`.
ClassificationTable := Array new: 255.
self initializeChars: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' to: #alphabetic.
self initializeChars: '01234567890' to: #digit.
self initializeChars: '!!%&*+,-/<=>?@\~|' to: #binary.
ClassificationTable at: 177 put: #binary. "plus-or-minus"
ClassificationTable at: 183 put: #binary. "centered dot"
ClassificationTable at: 215 put: #binary. "times"
ClassificationTable at: 247 put: #binary. "divide"
self initializeChars: '().:;[]^_' to: #special.
#(9 10 12 13 26 32) do: [:i | ClassificationTable at: i put: #separator]! !
Dictionary subclass: #BRSmallDictionary
instanceVariableNames: 'keys values size '
classVariableNames: ''
poolDictionaries: ''
category: 'Refactory-Parser'!
BRScanner initialize!
More information about the Squeak-dev
mailing list
|