compiler/PPCNotNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Oct 2014 23:01:54 +0000
changeset 398 b3e47bab2de6
parent 392 9b297f0d949c
child 414 0eaf09920532
permissions -rw-r--r--
Added teardown to PetitCompilerTests to clean up a generated parser after tests.

"{ Package: 'stx:goodies/petitparser/compiler' }"

PPCDelegateNode subclass:#PPCNotNode
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCNotNode methodsFor:'accessing'!

prefix
	^ #not
! !

!PPCNotNode methodsFor:'analysis'!

isFirstSetTerminal
	^ false
! !

!PPCNotNode methodsFor:'compiling'!

compileWith: compiler effect: effect id: id

	compiler startMethod: id.
	compiler addVariable: 'memento'.
	compiler add: (compiler smartRemember: child).
	
	compiler startTokenMode.
	compiler call: (child compileWith: compiler).
	compiler stopTokenMode.
	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
	] 
! !