View Javadoc
1   /* Generated by: ParserGeneratorCC: Do not edit this line. JJTParserState.java Version 1.1.4 */
2   package org.apache.commons.jexl3.parser;
3   
4   public class JJTParserState implements java.io.Serializable {
5     private java.util.List<Node> nodes;
6     private java.util.List<Integer> marks;
7   
8     /* number of nodes on stack */
9     private int sp;
10    /* current mark */
11    private int mk;
12    private boolean node_created;
13  
14    public JJTParserState() {
15      nodes = new java.util.ArrayList<Node>();
16      marks = new java.util.ArrayList<Integer>();
17      sp = 0;
18      mk = 0;
19    }
20  
21    /* Determines whether the current node was actually closed and
22       pushed.  This should only be called in the final user action of a
23       node scope. */
24    public boolean nodeCreated() {
25      return node_created;
26    }
27  
28    /* Call this to reinitialize the node stack.  It is called
29       automatically by the parser's ReInit() method. */
30    public void reset() {
31      nodes.clear();
32      marks.clear();
33      sp = 0;
34      mk = 0;
35    }
36  
37    /* Returns the root node of the AST.  It only makes sense to call
38       this after a successful parse. */
39    public Node rootNode() {
40      return nodes.get(0);
41    }
42  
43    /* Pushes a node on to the stack. */
44    public void pushNode(Node n) {
45      nodes.add(n);
46      ++sp;
47    }
48  
49    /* Returns the node on the top of the stack, and remove it from the
50       stack.  */
51    public Node popNode() {
52     --sp;
53      if (sp < mk) {
54        mk = marks.remove(marks.size()-1).intValue();
55      }
56      return nodes.remove(nodes.size()-1);
57    }
58  
59    /* Returns the node currently on the top of the stack. */
60    public Node peekNode() {
61      return nodes.get(nodes.size()-1);
62    }
63  
64    /* Returns the number of children on the stack in the current node
65       scope. */
66    public int nodeArity() {
67      return sp - mk;
68    }
69  
70    /* Parameter is currently unused. */
71    public void clearNodeScope(@SuppressWarnings("unused") final Node n) {
72      while (sp > mk) {
73        popNode();
74      }
75      mk = marks.remove(marks.size()-1).intValue();
76    }
77  
78    public void openNodeScope(final Node n) {
79      marks.add(Integer.valueOf(mk));
80      mk = sp;
81      n.jjtOpen();
82    }
83  
84    /* A definite node is constructed from a specified number of
85       children.  That number of nodes are popped from the stack and
86       made the children of the definite node.  Then the definite node
87       is pushed on to the stack. */
88    public void closeNodeScope(final Node n, final int numIn) {
89      mk = marks.remove(marks.size()-1).intValue();
90      int num = numIn;
91      while (num-- > 0) {
92        Node c = popNode();
93        c.jjtSetParent(n);
94        n.jjtAddChild(c, num);
95      }
96      n.jjtClose();
97      pushNode(n);
98      node_created = true;
99    }
100 
101 
102   /* A conditional node is constructed if its condition is true.  All
103      the nodes that have been pushed since the node was opened are
104      made children of the conditional node, which is then pushed
105      on to the stack.  If the condition is false the node is not
106      constructed and they are left on the stack. */
107   public void closeNodeScope(final Node n, final boolean condition) {
108     if (condition) {
109       int a = nodeArity();
110       mk = marks.remove(marks.size()-1).intValue();
111       while (a-- > 0) {
112         final Node c = popNode();
113         c.jjtSetParent(n);
114         n.jjtAddChild(c, a);
115       }
116       n.jjtClose();
117       pushNode(n);
118       node_created = true;
119     } else {
120       mk = marks.remove(marks.size()-1).intValue();
121       node_created = false;
122     }
123   }
124 }
125 /* ParserGeneratorCC - OriginalChecksum=3af257fee0bb681e8dd29aaeafa1b844 (do not edit this line) */