|ASTNode start()/end() invariants [message #901998]
||Wed, 15 August 2012 12:54
|| Jens von Pilgrim
Registered: July 2009
I'm wondering about certain invariants concerning the ranges of an
ASTNode. I'm not sure whether they are supposed to hold (in all
cases/languages) or not. I would say that they should hold for languages
such as Java, but I'm not sure whether there are some languages out
there for which they cannot hold.
For a given ASTNode n, the following invariants could be defined
2) n.getChilds().contains(c) -> c.start()>=n.start() && c.end()<=n.end()
3) n.getChilds().contains(c1) && n.getChilds().contains(c2) && c1!=c2
-> c1.end()<c2.start() || c2.end()<c1.start()
Invariant 1) is simple, but does it hold for ASTNodes in all cases?
Invariant 2) states that a child's range is to be contained in its
parent's range. However, this is not true e.g., in case of invalid parse
trees, e.g., due to parse errors.
Invariant 3) states that the ranges of two children must not overlap
(assuming inv. 1) holds). But I'm not sure whether this holds for all nodes.
Inv. 2) and 3) would enable more efficient searches in the AST using a
given position, as one would not have to search all children.
Powered by FUDForum
. Page generated in 0.01870 seconds