compiler/PPCTokenDetector.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 05 May 2015 15:07:56 +0200
changeset 450 914c2567c987
parent 438 20598d7ce9fa
child 452 9f4558b3be66
permissions -rw-r--r--
Oops, merged lost Smalltalk/X compatibility fixes

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

"{ NameSpace: Smalltalk }"

PPCRewritingVisitor subclass:#PPCTokenDetector
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Visitors'
!

!PPCTokenDetector methodsFor:'visiting'!

visitActionNode: node
	(node hasProperty: #trimmingToken) ifTrue: [ 
		| newWs newChild  |
		self change.

		newChild := self visitWithTokenVisitor: node child children second child. "Oups, what a chain"
		newWs := self visitWithTokenVisitor: node child children first.

		^ PPCTrimmingTokenNode new
			name: node name;
			child: newChild;
			tokenClass: node child children second tokenClass;
			whitespace: newWs;
			yourself.
	].

	^ super visitActionNode: node
!

visitNotNode: node
	"We don't need result of the not,..."
	| child newChild |
	self change.
	child := node child.
	newChild := self visitWithTokenVisitor: child.
	node replace: child with: newChild.
	^ node
!

visitTokenNode: node
	| child newChild |
	
	self change.
	child := node child.
	newChild := self visitWithTokenVisitor: child.
	node replace: child with: newChild.
	
	^ node
!

visitWithTokenVisitor: node
	| retval forbiddenNodes copyVisitor tokenVisitor |
	
	copyVisitor := PPCCopyVisitor new.
	tokenVisitor := PPCTokenVisitor new.
	
	forbiddenNodes := openSet copy.
	tokenVisitor forbiddenNodes: forbiddenNodes.

	retval := copyVisitor visit: node.
	retval := tokenVisitor visit: retval.
	^ retval
! !