Merged JK's work on PetitCompiler
Name: PetitCompiler-JanKurs.57
Author: JanKurs
Time: 05-11-2014, 05:10:47 AM
UUID: 4c625efe-77fd-465d-bd63-72ead0b5d3ba
Name: PetitCompiler-Tests-JanVrany.13
Author: JanVrany
Time: 05-11-2014, 09:31:07 AM
UUID: 189ae287-6bc1-40ba-8458-b8392c4260a0
"{ Package: 'stx:goodies/petitparser/compiler' }"
PPCDelegateNode subclass:#PPCNotNode
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Nodes'
!
!PPCNotNode methodsFor:'accessing'!
prefix
^ #not
! !
!PPCNotNode methodsFor:'analysis'!
firstCharSet
^ PPCharSetPredicate on: [:e | true ]
!
isFirstSetTerminal
^ true
! !
!PPCNotNode methodsFor:'compiling'!
compileWith: compiler effect: effect id: id
compiler startMethod: id.
compiler addVariable: 'memento'.
compiler add: (compiler smartRemember: child).
compiler call: (child compileWith: compiler).
compiler add: (compiler smartRestore: child).
compiler add: '^ error ifFalse: [ self error ] ifTrue: [ self clearError. nil ]'.
^ compiler stopMethod.
! !
!PPCNotNode methodsFor:'optimizing'!
optimize: params
(self rewrite: params) ifTrue: [
^ true.
].
^ super optimize: params.
!
rewrite: changeStatus
(child isKindOf: PPCAbstractLiteralNode) ifTrue: [
changeStatus change.
^ PPCNotLiteralNode new
name: self name;
literal: self child literal;
yourself
].
(child isKindOf: PPCMessagePredicateNode) ifTrue: [
changeStatus change.
^ PPCNotMessagePredicateNode new
name: self name;
message: child message;
yourself
].
(child isKindOf: PPCCharSetPredicateNode) ifTrue: [
changeStatus change.
^ PPCNotCharSetPredicateNode new
name: self name;
predicate: child predicate;
yourself
].
"Can do the fast version, because we throw away the result and return nil"
(self allNodes anySatisfy: [ :node | node asFast ~= node ]) ifTrue: [
changeStatus change.
self replace: child with: (child transform: [:node | node asFast]).
]
! !