#REFACTORING by exept
authorClaus Gittinger <cg@exept.de>
Fri, 23 Aug 2019 21:48:35 +0200
changeset 4522 1879f0459703
parent 4521 a71cca8701c9
child 4523 5498e118d969
#REFACTORING by exept class: ParseNode comment/format in: #containedBy: #startPosition: changed: #startPosition:endPosition: #whichNodeIsContainedBy:
ParseNode.st
--- a/ParseNode.st	Fri Aug 23 21:38:57 2019 +0200
+++ b/ParseNode.st	Fri Aug 23 21:48:35 2019 +0200
@@ -72,7 +72,9 @@
     ^ self
 !
 
-containedBy:anInterval 
+containedBy:anInterval
+    "true if the interval contains me completely"
+
     startPosition isNil ifTrue:[^ false].
     endPosition isNil ifTrue:[^ false].
     ^ anInterval first <= startPosition and:[anInterval last >= endPosition]
@@ -121,25 +123,29 @@
     ^ self "/ I intersect
 !
 
-whichNodeIsContainedBy: anInterval 
-    |childrenInInterval subChild|
+whichNodeIsContainedBy:anInterval 
+    |firstChildInInterval|
 
     (self intersectsInterval: anInterval) ifFalse: [^nil].
     (self containedBy: anInterval) ifTrue: [^self].
 
-    childrenInInterval := self children select: [:each | each intersectsInterval: anInterval].
-    childrenInInterval size == 0 ifTrue:[
+    self childrenDo:[:each | 
+        (each intersectsInterval:anInterval) ifTrue:[
+            firstChildInInterval notNil ifTrue:[
+                "/ ouch: multiple children in interval
+                self halt.
+                ^ self
+            ].
+            firstChildInInterval := each
+        ].
+    ].
+
+    firstChildInInterval isNil ifTrue:[
+        "/ no children in interval; so it must be me
         ^ self
     ].
-    childrenInInterval size == 1 ifTrue:[
-        subChild := childrenInInterval first whichNodeIsContainedBy:anInterval.
-        subChild notNil ifTrue:[
-            ^ subChild
-        ].
-        ^ self
-    ].
-    self halt.
-    ^ self
+    "/ look deeper
+    ^ firstChildInInterval whichNodeIsContainedBy:anInterval.
 ! !
 
 !ParseNode methodsFor:'accessing'!
@@ -263,8 +269,13 @@
         "/ a synthetic node
         "/ self halt.
     ] ifFalse:[
+        "/ nil end means: up-to-end (but only for error nodes)
         self assert:start > 0.
-        self assert:end >= start.
+        end isNil ifTrue:[
+            self assert:(self isErrorNode)
+        ] ifFalse:[
+            self assert:(end >= start).
+        ].
     ].
     startPosition := start.
     endPosition := end.