#REFACTORING by exept
class: ParseNode
comment/format in:
#containedBy:
#startPosition:
changed:
#startPosition:endPosition:
#whichNodeIsContainedBy:
--- 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.