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' }"
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:'as yet unclassified'!
firstCharSet
^ parser firstCharSet
! !
!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
! !