compiler/PPCActionNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 26 Oct 2014 01:28:07 +0000
changeset 392 9b297f0d949c
parent 391 553a5456963b
child 414 0eaf09920532
permissions -rw-r--r--
Fixed PPCNode>>doOptmizationLoop:status: Must report status to changeStatus as caller is checking its value. Also, added PPCOptimizationResult class>>new as Smaltalk/X (actually, most Smalltalks) does not call #initialize by default.

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

PPCAbstractActionNode subclass:#PPCActionNode
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCActionNode methodsFor:'as yet unclassified'!

compileWith: compiler effect: effect id: id
	compiler addConstant: block as: id.
	
	compiler startMethod: id.
	compiler addVariable: 'element'.
	compiler add: 'element := '.
	compiler callOnLine: (child compileWith: compiler).
	compiler add: 'error ifFalse: [ ^ ',  id, ' value: element ].'.
	compiler add: '^ failure'.
 ^ compiler stopMethod.
!

rewrite: changeStatus
	"TODO JK: Find another way how to recognize the trimming token!!"
	(name = 'trimmingToken') ifTrue: [ 
		changeStatus change.
		^ PPCTrimmingTokenNode new
			"name: name"
			"JK: I am sorry"
			child: child children second child;
			tokenClass: child children second tokenClass;
			whitespace: child children first;
			yourself
	].
	
	block isSymbol ifTrue: [ 
		changeStatus change.
		^ PPCSymbolActionNode new
			block: block;
			name: name;
			child: child;
			yourself
	]
! !