Updated to PetitCompiler-JanKurs.160, PetitCompiler-Tests-JanKurs.112, PetitCompiler-Extras-Tests-JanKurs.25, PetitCompiler-Benchmarks-JanKurs.17
Name: PetitCompiler-JanKurs.160
Author: JanKurs
Time: 17-08-2015, 09:52:26.291 AM
UUID: 3b4bfc98-8098-4951-af83-a59e2585b121
Name: PetitCompiler-Tests-JanKurs.112
Author: JanKurs
Time: 16-08-2015, 05:00:32.936 PM
UUID: 85613d47-08f3-406f-9823-9cdab451e805
Name: PetitCompiler-Extras-Tests-JanKurs.25
Author: JanKurs
Time: 16-08-2015, 05:00:10.328 PM
UUID: 09731810-51a1-4151-8d3a-56b636fbd1f7
Name: PetitCompiler-Benchmarks-JanKurs.17
Author: JanKurs
Time: 05-08-2015, 05:29:32.407 PM
UUID: e544b5f1-bcf8-470b-93a6-d2363e4dfc8a
"{ Package: 'stx:goodies/petitparser/gui' }"
Refactoring subclass:#PPDefineProdcutionRefactoring
instanceVariableNames:'class source protocols method'
classVariableNames:''
poolDictionaries:''
category:'PetitGui-Refactoring'
!
!PPDefineProdcutionRefactoring class methodsFor:'instance creation'!
onClass: aClass source: aString protocols: anArray
^ self new
setClass: aClass;
setSource: aString;
setProtocols: anArray;
yourself
! !
!PPDefineProdcutionRefactoring methodsFor:'accessing'!
selector
^ method selector
! !
!PPDefineProdcutionRefactoring methodsFor:'initialization'!
setClass: aClass
class := self classObjectFor: aClass
!
setProtocols: anArray
protocols := anArray
!
setSource: aString
source := aString
! !
!PPDefineProdcutionRefactoring methodsFor:'preconditions'!
preconditions
^ (self checkCompositeParser: class)
& (RBCondition withBlock: [ self checkSource ] errorString: 'Unable to parse source code')
! !
!PPDefineProdcutionRefactoring methodsFor:'private'!
checkSource
| rewriter |
method := RBParser
parseMethod: source
onError: [ :string :position | ^ false ].
rewriter := self sourceRewriter.
[ rewriter executeTree: method ]
whileTrue: [ method := rewriter tree ].
^ method selector isUnary
!
sourceRewriter
^ ParseTreeRewriter new
replace: '`#literal' with: '`#literal asParser' when: [ :node |
(node isLiteralNode and: [ node value isString or: [ node value isCharacter ] ])
and: [ (node parent isNil or: [ node parent isMessage not or: [ node parent selector ~= #asParser ] ])
and: [ (node parents noneSatisfy: [ :each | each isBlock ]) ] ] ];
replaceMethod: '`@method: `@args | `@temps | ``@.statements. ``.statement `{ :node | node isReturn not }'
with: '`@method: `@args | `@temps | ``@.statements. ^ ``.statement';
yourself
! !
!PPDefineProdcutionRefactoring methodsFor:'transforming'!
transform
(class definesInstanceVariable: method selector asString)
ifFalse: [ class addInstanceVariable: method selector asString ].
class compile: method newSource classified: protocols
! !
!PPDefineProdcutionRefactoring class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/PPDefineProdcutionRefactoring.st,v 1.1 2014-03-04 21:15:26 cg Exp $'
!
version_CVS
^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/PPDefineProdcutionRefactoring.st,v 1.1 2014-03-04 21:15:26 cg Exp $'
! !