~ubuntu-branches/ubuntu/vivid/herold/vivid

« back to all changes in this revision

Viewing changes to java/org/dbdoclet/trafo/xml/tokenizer/parser/JJTXmlTokenizerState.java

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2012-09-20 10:00:14 UTC
  • Revision ID: package-import@ubuntu.com-20120920100014-5pcwbw2err6on8yg
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (C) 2001-2012 Michael Fuchs
 
3
 *
 
4
 * This file is part of herold.
 
5
 * 
 
6
 * herold is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * herold is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with herold.  If not, see <http://www.gnu.org/licenses/>.  
 
18
 */
 
19
package org.dbdoclet.trafo.xml.tokenizer.parser;
 
20
 
 
21
@SuppressWarnings("all")
 
22
public class JJTXmlTokenizerState {
 
23
  private java.util.List<Node> nodes;
 
24
  private java.util.List<Integer> marks;
 
25
 
 
26
  private int sp;        // number of nodes on stack
 
27
  private int mk;        // current mark
 
28
  private boolean node_created;
 
29
 
 
30
  public JJTXmlTokenizerState() {
 
31
    nodes = new java.util.ArrayList<Node>();
 
32
    marks = new java.util.ArrayList<Integer>();
 
33
    sp = 0;
 
34
    mk = 0;
 
35
  }
 
36
 
 
37
  /* Determines whether the current node was actually closed and
 
38
     pushed.  This should only be called in the final user action of a
 
39
     node scope.  */
 
40
  public boolean nodeCreated() {
 
41
    return node_created;
 
42
  }
 
43
 
 
44
  /* Call this to reinitialize the node stack.  It is called
 
45
     automatically by the parser's ReInit() method. */
 
46
  public void reset() {
 
47
    nodes.clear();
 
48
    marks.clear();
 
49
    sp = 0;
 
50
    mk = 0;
 
51
  }
 
52
 
 
53
  /* Returns the root node of the AST.  It only makes sense to call
 
54
     this after a successful parse. */
 
55
  public Node rootNode() {
 
56
    return nodes.get(0);
 
57
  }
 
58
 
 
59
  /* Pushes a node on to the stack. */
 
60
  public void pushNode(Node n) {
 
61
    nodes.add(n);
 
62
    ++sp;
 
63
  }
 
64
 
 
65
  /* Returns the node on the top of the stack, and remove it from the
 
66
     stack.  */
 
67
  public Node popNode() {
 
68
    if (--sp < mk) {
 
69
      mk = marks.remove(marks.size()-1);
 
70
    }
 
71
    return nodes.remove(nodes.size()-1);
 
72
  }
 
73
 
 
74
  /* Returns the node currently on the top of the stack. */
 
75
  public Node peekNode() {
 
76
    return nodes.get(nodes.size()-1);
 
77
  }
 
78
 
 
79
  /* Returns the number of children on the stack in the current node
 
80
     scope. */
 
81
  public int nodeArity() {
 
82
    return sp - mk;
 
83
  }
 
84
 
 
85
 
 
86
  public void clearNodeScope(Node n) {
 
87
    while (sp > mk) {
 
88
      popNode();
 
89
    }
 
90
    mk = marks.remove(marks.size()-1);
 
91
  }
 
92
 
 
93
 
 
94
  public void openNodeScope(Node n) {
 
95
    marks.add(mk);
 
96
    mk = sp;
 
97
    n.jjtOpen();
 
98
  }
 
99
 
 
100
 
 
101
  /* A definite node is constructed from a specified number of
 
102
     children.  That number of nodes are popped from the stack and
 
103
     made the children of the definite node.  Then the definite node
 
104
     is pushed on to the stack. */
 
105
  public void closeNodeScope(Node n, int num) {
 
106
    mk = marks.remove(marks.size()-1);
 
107
    while (num-- > 0) {
 
108
      Node c = popNode();
 
109
      c.jjtSetParent(n);
 
110
      n.jjtAddChild(c, num);
 
111
    }
 
112
    n.jjtClose();
 
113
    pushNode(n);
 
114
    node_created = true;
 
115
  }
 
116
 
 
117
 
 
118
  /* A conditional node is constructed if its condition is true.  All
 
119
     the nodes that have been pushed since the node was opened are
 
120
     made children of the conditional node, which is then pushed
 
121
     on to the stack.  If the condition is false the node is not
 
122
     constructed and they are left on the stack. */
 
123
  public void closeNodeScope(Node n, boolean condition) {
 
124
    if (condition) {
 
125
      int a = nodeArity();
 
126
      mk = marks.remove(marks.size()-1);
 
127
      while (a-- > 0) {
 
128
        Node c = popNode();
 
129
        c.jjtSetParent(n);
 
130
        n.jjtAddChild(c, a);
 
131
      }
 
132
      n.jjtClose();
 
133
      pushNode(n);
 
134
      node_created = true;
 
135
    } else {
 
136
      mk = marks.remove(marks.size()-1);
 
137
      node_created = false;
 
138
    }
 
139
  }
 
140
}
 
141
/* JavaCC - OriginalChecksum=0e9cbe71823ea05b1e3a7d05f900850d (do not edit this line) */