compiler/PPCUnknownNode.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' }"

PPCNode subclass:#PPCUnknownNode
	instanceVariableNames:'parser'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCUnknownNode methodsFor:'accessing'!

acceptsEpsilon
	^ parser acceptsEpsilon
!

acceptsEpsilonOpenSet: aSet
	^ parser acceptsEpsilonOpenSet: aSet
!

children
	^ parser children
!

firstCharParser
	^ parser firstCharParser
!

isContextFreePrim
	^ parser isContextFreePrim
!

parser
	
	^ parser
!

parser: anObject
	
	parser := anObject
!

prefix
	^ #parser
! !

!PPCUnknownNode methodsFor:'compiling'!

compileWith: compiler effect: effect id: id
	| compiledChild compiledParser |
	compiler startMethod: id.
	
	compiledParser := parser copy.
	"Compile all the children and call compiled version of them instead of the original one"
	compiledParser children do: [ :child | 
		compiledChild := child compileWith: compiler.
		compiledParser replace: child with: compiledChild bridge.
	].
	
	compiler addConstant: compiledParser as: id. 
	
	compiler addVariable: 'retval'.
	compiler add: 'self clearError.'.
	compiler add: '(retval := ', id, ' parseOn: context) isPetitFailure'.
	compiler indent.
	compiler add: ' ifTrue: [self error: retval message at: retval position ].'.
	compiler dedent.
	compiler add: 'error := retval isPetitFailure.'.
	compiler add: '^ retval'.
 ^ compiler stopMethod.
! !

!PPCUnknownNode methodsFor:'transformation'!

replace: node with: anotherNode
	parser replace: node with: anotherNode
! !