01: package persistence.antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: import persistence.antlr.collections.AST;
10:
11: /** ASTPair: utility class used for manipulating a pair of ASTs
12: * representing the current AST root and current AST sibling.
13: * This exists to compensate for the lack of pointers or 'var'
14: * arguments in Java.
15: */
16: public class ASTPair {
17: public AST root; // current root of tree
18: public AST child; // current child to which siblings are added
19:
20: /** Make sure that child is the last sibling */
21: public final void advanceChildToEnd() {
22: if (child != null) {
23: while (child.getNextSibling() != null) {
24: child = child.getNextSibling();
25: }
26: }
27: }
28:
29: /** Copy an ASTPair. Don't call it clone() because we want type-safety */
30: public ASTPair copy() {
31: ASTPair tmp = new ASTPair();
32: tmp.root = root;
33: tmp.child = child;
34: return tmp;
35: }
36:
37: public String toString() {
38: String r = root == null ? "null" : root.getText();
39: String c = child == null ? "null" : child.getText();
40: return "[" + r + "," + c + "]";
41: }
42: }
|