Merged with PetitCompiler-JanKurs.20150510144201, PetitCompiler-Tests-JanKurs.20150510144201, PetitCompiler-Extras-Tests-JanKurs.20150510144201, PetitCompiler-Benchmarks-JanKurs.20150510144201
Name: PetitCompiler-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 04:42:29.192 PM
UUID: 58a4786b-1182-4904-8b44-a13d3918f244
Name: PetitCompiler-Tests-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 04:32:12.870 PM
UUID: 2a8fd41a-331b-4dcf-a7a3-752a50ce86e7
Name: PetitCompiler-Extras-Tests-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 04:59:25.308 PM
UUID: ef43bd1a-be60-4e88-b749-8b635622c969
Name: PetitCompiler-Benchmarks-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 05:04:54.561 PM
UUID: d8e764fd-016b-46e2-9fc1-17c38c18f0e5
"{ Package: 'stx:goodies/petitparser/compiler' }"
"{ NameSpace: Smalltalk }"
PPCRewritingVisitor subclass:#PPCTokenDetector
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Visitors'
!
!PPCTokenDetector methodsFor:'as yet unclassified'!
visitActionNode: node
(node hasProperty: #trimmingToken) ifTrue: [
| child whitespace |
self change.
child := self visitWithTokenVisitor: node child secondChild.
whitespace := self visitWithTokenVisitor: node child firstChild.
^ PPCTrimmingTokenNode new
name: node name;
child: child;
whitespace: whitespace;
tokenClass: node child secondChild tokenClass;
properties: node properties copy;
yourself.
].
^ super visitActionNode: node
!
visitTokenNode: node
| child newChild |
self change.
child := node child.
newChild := self visitWithTokenVisitor: node child.
node replace: child with: newChild.
^ node
!
visitTrimNode: node
self visitChildren: node.
(node child isKindOf: PPCTokenNode) ifTrue: [
self change.
^ PPCTrimmingTokenNode new
name: node name;
child: node child child;
tokenClass: node child tokenClass;
whitespace: node trimmer;
yourself
].
(node child isKindOf: PPCTokenConsumeNode) ifTrue: [
self change.
^ PPCTrimmingTokenNode new
name: node name;
child: node child;
tokenClass: node child child tokenClass;
whitespace: node trimmer;
yourself
].
^ 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
! !