compiler/PPCTokenNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 26 Oct 2014 22:00:05 +0000
changeset 393 00381102a9b5
parent 392 9b297f0d949c
child 414 0eaf09920532
permissions -rw-r--r--
Override #new in classes that implement #initialize. Not all Smalltalks call #initialize automatically. Actually, mose of them does not.

"{ 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.

    "Modified: / 26-10-2014 / 01:34:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

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 startTokenMode.
	compiler addVariable: 'start'.
	compiler addVariable: 'end'.
	
"
	(compiler guards and: [ (guardSet := compiler guardCharSet: self) isNil not ]) ifTrue: [ 	
		guardSetId := (compiler idFor: guardSet prefixed: #guard).
		compiler addConstant: guardSet as: guardSetId.
		compiler add: 'context atEnd ifTrue: [ ^ self error ].'.
		compiler add: '(', guardSetId, ' value: context peek) ifFalse: [ ^ self error ].'.
	].
"
	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 stopTokenMode.
 ^ compiler stopMethod.	
!

prefix
	^ #token
! !