compiler/PPCTokenNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 01 Nov 2014 00:30:28 +0000
changeset 403 7063d523b064
parent 393 00381102a9b5
child 414 0eaf09920532
permissions -rw-r--r--
Removed autoload attribut for tests. As all classes are in a test package, when package is loaded likely tests are required, so load them right away.

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