compiler/PPCTokenNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 05 Nov 2014 23:05:19 +0000
changeset 414 0eaf09920532
parent 393 00381102a9b5
child 421 7e08b31e0dae
permissions -rw-r--r--
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' }"

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

!PPCTokenNode class methodsFor:'instance creation'!

new
    "return an initialized instance"

    ^ self basicNew initialize.
! !

!PPCTokenNode methodsFor:'accessing'!

initialize
	super initialize.
!

rewrite: changeStatus
	|  |
	super rewrite: changeStatus.
	
	(self allNodes anySatisfy: [ :node | node asFast ~= node ]) ifTrue: [  
		changeStatus change.
		self replace: child with: (child transform: [:node | node asFast]).
	]
!

tokenClass
	
	^ tokenClass
!

tokenClass: anObject
	
	tokenClass := anObject
! !

!PPCTokenNode methodsFor:'as yet unclassified'!

compileWith: compiler effect: effect id: id
	|    |

	compiler startMethod: id.
	compiler addVariable: 'start'.
	compiler addVariable: 'end'.
	
	compiler add: 'start := context position + 1.'.
	compiler call: (self child compileWith: compiler).
	compiler add: 'error ifTrue: [ ^ self ].'.	
	compiler add: 'end := context position.'.
	
	compiler add: '^ ', tokenClass asString, ' on: (context collection) 
																start: start  
																stop: end
																value: nil'.
 ^ compiler stopMethod.	
!

prefix
	^ #token
! !