compiler/PPCTrimmingTokenNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Apr 2015 23:43:14 +0200
changeset 438 20598d7ce9fa
parent 422 116d2b2af905
child 452 9f4558b3be66
permissions -rw-r--r--
Updated to PetitCompiler-JanKurs.100, PetitCompiler-Tests-JanKurs.44 and PetitCompiler-Benchmarks-JanKurs.4 Name: PetitCompiler-JanKurs.100 Author: JanKurs Time: 30-04-2015, 10:48:52.165 AM UUID: 80196870-5921-46d9-ac20-a43bf5c2f3c2 Name: PetitCompiler-Tests-JanKurs.44 Author: JanKurs Time: 30-04-2015, 10:49:22.489 AM UUID: 348c02e8-18ce-48f6-885d-fcff4516a298 Name: PetitCompiler-Benchmarks-JanKurs.4 Author: JanKurs Time: 30-04-2015, 10:58:44.890 AM UUID: 18cadb42-f9ef-45fb-82e9-8469ade56c8b

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

PPCListNode subclass:#PPCTrimmingTokenNode
	instanceVariableNames:'tokenClass'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCTrimmingTokenNode methodsFor:'accessing'!

child
	
	^ children at: 2
!

child: anObject
	
	children at: 2 put: anObject
!

prefix
	^ #token
!

tokenClass
	
	^ tokenClass
!

tokenClass: anObject
	
	tokenClass := anObject
!

whitespace
	
	^ children at: 1
!

whitespace: anObject
	(anObject name isNil and: [ self child name isNotNil ]) ifTrue: [ 
		anObject name: self child name, '_ws'.
	].
	children at: 1 put: anObject
! !

!PPCTrimmingTokenNode methodsFor:'analyzing'!

acceptsEpsilon
	^ self child acceptsEpsilonOpenSet: (IdentitySet with: self).
!

acceptsEpsilonOpenSet: set
	(set includes: self child) ifFalse: [ 
		set add: self child.
		^ self child acceptsEpsilonOpenSet: set 
	].
	^ false
!

firstSetSuchThat: block into: aCollection openSet: aSet
	(aSet includes: self) ifTrue: [ ^ aCollection ].
	aSet add: self.
	
	(block value: self) ifTrue: [ aCollection add: self. ^ aCollection ].
	
	^ self child firstSetSuchThat: block into: aCollection openSet: aSet.
!

firstSets: aFirstDictionary into: aSet suchThat: aBlock
	"PRIVATE: Try to add additional elements to the first-set aSet of the receiver, use the incomplete aFirstDictionary."

	(aBlock value: self) ifFalse: [ 
		aSet addAll: (aFirstDictionary at: self child)
	]
! !

!PPCTrimmingTokenNode methodsFor:'comparing'!

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

hash
	^ super hash bitXor: tokenClass hash
! !

!PPCTrimmingTokenNode methodsFor:'initialization'!

initialize
	super initialize.
	children := Array new: 2
! !

!PPCTrimmingTokenNode methodsFor:'visiting'!

accept: visitor
	^ visitor visitTrimmingTokenNode: self
! !