compiler/PPCActionNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 15 Apr 2015 11:28:09 +0100
changeset 422 116d2b2af905
parent 421 7e08b31e0dae
child 438 20598d7ce9fa
permissions -rw-r--r--
To fold

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

"{ NameSpace: Smalltalk }"

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

!PPCActionNode methodsFor:'as yet unclassified'!

asFast
	^ PPCTokenActionNode new
		child: child;
		properties: properties;
		name: self name;
		yourself
!

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
	(self hasProperty: #trimmingToken) ifTrue: [ 
		changeStatus change.
		^ PPCTrimmingTokenNode new
			name: name;
			child: child children second child; 				"Oups, what a chain"
			tokenClass: child children second tokenClass;
			whitespace: child children first;
			yourself
	].
	
	block isSymbol ifTrue: [ 
		changeStatus change.
		^ PPCSymbolActionNode new
			block: block;
			name: name;
			child: child;
			yourself
	]
! !