compiler/PPCTokenDetector.st
changeset 452 9f4558b3be66
parent 438 20598d7ce9fa
child 515 b5316ef15274
--- a/compiler/PPCTokenDetector.st	Thu Apr 30 23:43:14 2015 +0200
+++ b/compiler/PPCTokenDetector.st	Sun May 10 06:28:36 2015 +0100
@@ -9,59 +9,76 @@
 	category:'PetitCompiler-Visitors'
 !
 
-!PPCTokenDetector methodsFor:'visiting'!
+!PPCTokenDetector methodsFor:'as yet unclassified'!
 
-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.
+visitActionNode: node	
 
-		^ PPCTrimmingTokenNode new
-			name: node name;
-			child: newChild;
-			tokenClass: node child children second tokenClass;
-			whitespace: newWs;
-			yourself.
-	].
+    (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
+    ^ 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: node 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
+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 forbiddenNodes copyVisitor tokenVisitor |
+    
+    copyVisitor := PPCCopyVisitor new.
+    tokenVisitor := PPCTokenVisitor new.
+    
+    forbiddenNodes := openSet copy.
+    tokenVisitor forbiddenNodes: forbiddenNodes.
 
-	retval := copyVisitor visit: node.
-	retval := tokenVisitor visit: retval.
-	^ retval
+    retval := copyVisitor visit: node.
+    retval := tokenVisitor visit: retval.
+    ^ retval
 ! !