nitc :: ANode :: common_parent
self
and other
Return null if the two node are unrelated (distinct root)
# The most specific common parent between `self` and `other`
# Return null if the two node are unrelated (distinct root)
fun common_parent(other: ANode): nullable ANode
do
# First, get the same depth
var s: nullable ANode = self
var o: nullable ANode = other
var d = s.depth - o.depth
while d > 0 do
s = s.parent
d -= 1
end
while d < 0 do
o = o.parent
d += 1
end
assert o.depth == s.depth
# Second, go up until same in found
while s != o do
s = s.parent
o = o.parent
end
return s
end
src/parser/parser_nodes.nit:75,2--98,4