#OTHER by exept
authorClaus Gittinger <cg@exept.de>
Thu, 22 Aug 2019 17:54:46 +0200
changeset 4506 c5b6671d3761
parent 4505 08c446ddef55
child 4507 f61494fda739
#OTHER by exept fixed child enumeration for explainer
ParseNode.st
--- a/ParseNode.st	Thu Aug 22 17:54:43 2019 +0200
+++ b/ParseNode.st	Thu Aug 22 17:54:46 2019 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
@@ -56,7 +58,18 @@
 !ParseNode methodsFor:'RBParser compatibility'!
 
 children
-    ^ ParseNodeVisitor collectChildrenOf:self
+    |children|
+
+    children := OrderedCollection new.
+    self childrenDo:[:each |
+        self assert:(each notNil).
+        children add:each
+    ].
+    ^ children.
+!
+
+childrenDo:aBlock
+    ^ self
 !
 
 containedBy:anInterval 
@@ -109,16 +122,24 @@
 !
 
 whichNodeIsContainedBy: anInterval 
-    | selectedChildren |
+    |childrenInInterval subChild|
 
     (self intersectsInterval: anInterval) ifFalse: [^nil].
     (self containedBy: anInterval) ifTrue: [^self].
 
-    selectedChildren := self children 
-                            select: [:each | each intersectsInterval: anInterval].
-    ^ selectedChildren size == 1 
-            ifTrue: [selectedChildren first whichNodeIsContainedBy: anInterval]
-            ifFalse: [nil]
+    childrenInInterval := self children select: [:each | each intersectsInterval: anInterval].
+    childrenInInterval size == 0 ifTrue:[
+        ^ self
+    ].
+    childrenInInterval size == 1 ifTrue:[
+        subChild := childrenInInterval first whichNodeIsContainedBy:anInterval.
+        subChild notNil ifTrue:[
+            ^ subChild
+        ].
+        ^ self
+    ].
+    self halt.
+    ^ self
 ! !
 
 !ParseNode methodsFor:'accessing'!
@@ -143,6 +164,7 @@
 !
 
 endPosition:aCharacterPosition
+    self assert:aCharacterPosition >= 1.
 
     endPosition := aCharacterPosition
 
@@ -230,13 +252,20 @@
 !
 
 startPosition:start
-
+    self assert:start > 0.
     startPosition := start
 
     "Modified: / 08-04-2011 / 22:03:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-startPosition:start endPosition: end
+startPosition:start endPosition:end
+    (start == -1 and:[end == -1]) ifTrue:[
+        "/ a synthetic node
+        "/ self halt.
+    ] ifFalse:[
+        self assert:start > 0.
+        self assert:end >= start.
+    ].
     startPosition := start.
     endPosition := end.
 
@@ -475,6 +504,31 @@
     ^ self
 !
 
+statements:statements do:aBlock
+    |s|
+
+    statements isNil ifTrue:[^ self].
+
+    "/ temporary hack
+    statements isCollection ifTrue:[
+        statements do:aBlock.
+    ] ifFalse:[
+        "/ bad hack
+        (statements isKindOf:StatementNode) ifTrue:[
+            s := statements.
+            [ s notNil ] whileTrue:[
+                aBlock value:s.
+                s := s nextStatement
+            ].
+        ] ifFalse:[
+            "/ an innerblock node
+            aBlock value:statements.
+        ].
+    ].
+
+    "Modified: / 10-07-2019 / 02:32:21 / Claus Gittinger"
+!
+
 variableNodesDo:aBlock
     "evaluate aBlock for each variable-node here and in subnodes"
 
@@ -567,6 +621,10 @@
     ^ false
 !
 
+parseNodeVisitorClass
+    ^ ParseNodeVisitor
+!
+
 positionToInsertPeriodForStatementSeparation
     ^ self endPosition + (parenthized == true ifTrue:1 ifFalse:0)