View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  /* Generated By:JJTree: Do not edit this line. /export/home/develop/workspace/tuigwaa/src/java/com/isenshi/wiki/engine/JJTWikiParserState.java */
17  
18  package org.seasar.tuigwaa.cms.core.wiki.engine;
19  
20  class JJTWikiParserState {
21    private java.util.Stack nodes;
22    private java.util.Stack marks;
23  
24    private int sp;		// number of nodes on stack
25    private int mk;		// current mark
26    private boolean node_created;
27  
28    JJTWikiParserState() {
29      nodes = new java.util.Stack();
30      marks = new java.util.Stack();
31      sp = 0;
32      mk = 0;
33    }
34  
35    /* Determines whether the current node was actually closed and
36       pushed.  This should only be called in the final user action of a
37       node scope.  */
38    boolean nodeCreated() {
39      return node_created;
40    }
41  
42    /* Call this to reinitialize the node stack.  It is called
43       automatically by the parser's ReInit() method. */
44    void reset() {
45      nodes.removeAllElements();
46      marks.removeAllElements();
47      sp = 0;
48      mk = 0;
49    }
50  
51    /* Returns the root node of the AST.  It only makes sense to call
52       this after a successful parse. */
53    Node rootNode() {
54      return (Node)nodes.elementAt(0);
55    }
56  
57    /* Pushes a node on to the stack. */
58    void pushNode(Node n) {
59      nodes.push(n);
60      ++sp;
61    }
62  
63    /* Returns the node on the top of the stack, and remove it from the
64       stack.  */
65    Node popNode() {
66      if (--sp < mk) {
67        mk = ((Integer)marks.pop()).intValue();
68      }
69      return (Node)nodes.pop();
70    }
71  
72    /* Returns the node currently on the top of the stack. */
73    Node peekNode() {
74      return (Node)nodes.peek();
75    }
76  
77    /* Returns the number of children on the stack in the current node
78       scope. */
79    int nodeArity() {
80      return sp - mk;
81    }
82  
83  
84    void clearNodeScope(Node n) {
85      while (sp > mk) {
86        popNode();
87      }
88      mk = ((Integer)marks.pop()).intValue();
89    }
90  
91  
92    void openNodeScope(Node n) {
93      marks.push(new Integer(mk));
94      mk = sp;
95      n.jjtOpen();
96    }
97  
98  
99    /* A definite node is constructed from a specified number of
100      children.  That number of nodes are popped from the stack and
101      made the children of the definite node.  Then the definite node
102      is pushed on to the stack. */
103   void closeNodeScope(Node n, int num) {
104     mk = ((Integer)marks.pop()).intValue();
105     while (num-- > 0) {
106       Node c = popNode();
107       c.jjtSetParent(n);
108       n.jjtAddChild(c, num);
109     }
110     n.jjtClose();
111     pushNode(n);
112     node_created = true;
113   }
114 
115 
116   /* A conditional node is constructed if its condition is true.  All
117      the nodes that have been pushed since the node was opened are
118      made children of the the conditional node, which is then pushed
119      on to the stack.  If the condition is false the node is not
120      constructed and they are left on the stack. */
121   void closeNodeScope(Node n, boolean condition) {
122     if (condition) {
123       int a = nodeArity();
124       mk = ((Integer)marks.pop()).intValue();
125       while (a-- > 0) {
126 	Node c = popNode();
127 	c.jjtSetParent(n);
128 	n.jjtAddChild(c, a);
129       }
130       n.jjtClose();
131       pushNode(n);
132       node_created = true;
133     } else {
134       mk = ((Integer)marks.pop()).intValue();
135       node_created = false;
136     }
137   }
138 }