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

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

!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
! !

!PPCTokenNode methodsFor:'comparing'!

= anotherNode
	super = anotherNode ifFalse: [ ^ false ].
	^ tokenClass = anotherNode tokenClass.
!

hash
	^ super hash bitXor: tokenClass hash
! !