KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejen > ext > parsers > java_1_2 > Token


1 /* Generated By:JavaCC: Do not edit this line. Token.java Version 2.1 */
2 //
3
// Ejen (code generation system)
4
// Copyright (C) 2001, 2002 François Wolff (ejen@noos.fr).
5
//
6
// This file is part of Ejen.
7
//
8
// Ejen is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 2 of the License, or
11
// (at your option) any later version.
12
//
13
// Ejen is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// along with Ejen; if not, write to the Free Software
20
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
//
22
package org.ejen.ext.parsers.java_1_2;
23
24 // New ---------------------------
25
import org.ejen.util.arl.ArlUtil;
26
27 // --------------------------- New
28
/**
29  * Modification of the <code>Token</code> class generated by
30  * <a HREF="http://www.webgain.com/products/java_cc/">JavaCC</a>.
31  * @author F. Wolff
32  * @version 1.0
33  */

34 public class Token {
35
36     /**
37      * An integer that describes the kind of this token. This numbering
38      * system is determined by JavaCCParser, and a table of these numbers is
39      * stored in the file ...Constants.java.
40      */

41     public int kind;
42
43     /**
44      * beginLine and beginColumn describe the position of the first character
45      * of this token; endLine and endColumn describe the position of the
46      * last character of this token.
47      */

48     public int beginLine, beginColumn, endLine, endColumn;
49
50     /**
51      * The string image of the token.
52      */

53     public String JavaDoc image;
54
55     /**
56      * A reference to the next regular (non-special) token from the input
57      * stream. If this is the last token from the input stream, or if the
58      * token manager has not read tokens beyond this one, this field is
59      * set to null. This is true only if this token is also a regular
60      * token. Otherwise, see below for a description of the contents of
61      * this field.
62      */

63     public Token next;
64
65     /**
66      * This field is used to access special tokens that occur prior to this
67      * token, but after the immediately preceding regular (non-special) token.
68      * If there are no such special tokens, this field is set to null.
69      * When there are more than one such special token, this field refers
70      * to the last of these special tokens, which in turn refers to the next
71      * previous special token through its specialToken field, and so on
72      * until the first special token (whose specialToken field is null).
73      * The next fields of special tokens refer to other special tokens that
74      * immediately follow it (without an intervening regular token). If there
75      * is no such token, this field is null.
76      */

77     public Token specialToken;
78
79     /**
80      * Returns the image.
81      */

82     public final String JavaDoc toString() {
83         return image;
84     }
85
86     /**
87      * Returns a new Token object, by default. However, if you want, you
88      * can create and return subclass objects based on the value of ofKind.
89      * Simply add the cases to the switch for all those special cases.
90      * For example, if you have a subclass of Token called IDToken that
91      * you want to create if ofKind is ID, simlpy add something like :
92      *
93      * case MyParserConstants.ID : return new IDToken();
94      *
95      * to the following switch statement. Then you can cast matchedToken
96      * variable to the appropriate type and use it in your lexical actions.
97      */

98     public static final Token newToken(int ofKind) {
99         switch (ofKind) {
100         default:
101             return new Token();
102         }
103     }
104
105     // New ---------------------------
106
/**
107      * Creates a child DOM node appended to the 'parent' node, depending on the
108      * 'tokensMap' parameter. The child node will have the following structure:
109      * <p>
110      * <table class="usage"><tr><td class="usage"><pre>
111      *
112      * &lt;tok ki="72"&gt;&lt;![CDATA[ejen]]&gt;&lt;/tok&gt;
113      *
114      * <i>or, if tokensPos is true,</i>
115      *
116      * &lt;tok bc="13" bl="22" ec="16" el="22" ki="72"&gt;
117      * &lt;![CDATA[ejen]]&gt;
118      * &lt;/tok&gt;
119      * </pre></td></tr></table>
120      * <p>
121      * meaning that the token "ejen" of kind 72 ({@link JavaParserConstants#IDENTIFIER})
122      * begins in the source file at the (22,13) line,column coordinates and ends at
123      * the (22,16) coordinates. Token nodes may also have nested special token nodes.
124      * <p>
125      * See also {@link org.ejen.util.arl.ArlUtil}.
126      * <p>
127      * @param doc the Document in which the nodes are to be created.
128      * @param parent the DOM node to which the new Node must be appended.
129      * @param tokensMap an <code>int</code> array specifying, for each Token
130      * kind, if this node must accepted (created), crossed (only the
131      * CDATA section is created without a parent &lt;tok...&gt; node creation)
132      * or removed (no node creation, no CDATA section).
133      * @param tokensPos if true, this Token position coordinates will be includes
134      * as attributes.
135      * @throws org.w3c.dom.DOMException DOM errors...
136      */

137     public final void toNode(org.w3c.dom.Document JavaDoc doc,
138             org.w3c.dom.Node JavaDoc parent,
139             int[] tokensMap,
140             boolean tokensPos)
141         throws org.w3c.dom.DOMException JavaDoc {
142         if (tokensMap[kind] == ArlUtil.F_REMOVE) {
143             return;
144         }
145         if (tokensMap[kind] == ArlUtil.F_ACCEPT) {
146             org.w3c.dom.Element JavaDoc elt = doc.createElement("tok");
147
148             elt.setAttribute("ki", String.valueOf(kind));
149             if (tokensPos) {
150                 elt.setAttribute("bl", String.valueOf(beginLine));
151                 elt.setAttribute("bc", String.valueOf(beginColumn));
152                 elt.setAttribute("el", String.valueOf(endLine));
153                 elt.setAttribute("ec", String.valueOf(endColumn));
154             }
155             parent.appendChild(elt);
156             parent = elt;
157         }
158         Token st = specialToken;
159
160         if (st != null) {
161             while (st.specialToken != null) {
162                 st = st.specialToken;
163             }
164             while (st != null) {
165                 st.toSpecialNode(doc, parent, tokensMap, tokensPos);
166                 st = st.next;
167             }
168         }
169         parent.appendChild(doc.createCDATASection(image));
170     }
171
172     /**
173      * Creates a child 'stok' DOM node allways appended to a 'tok' parent node, depending on the
174      * 'tokensMap' parameter. The child node will have the following structure:
175      * <p>
176      * <table class="usage"><tr><td class="usage"><pre>
177      *
178      * &lt;stok ki="10"&gt;&lt;![CDATA[&#047;** Javadoc comment *&#047;]]&gt;&lt;/stok&gt;
179      *
180      * <i>or, if tokensPos is true,</i>
181      *
182      * &lt;stok bc="13" bl="22" ec="16" el="22" ki="10"&gt;
183      * &lt;![CDATA[&#047;** Javadoc comment *&#047;]]&gt;
184      * &lt;/stok&gt;
185      * </pre></td></tr></table>
186      * <p>
187      * meaning that the special token of kind 10 ({@link JavaParserConstants#FORMAL_COMMENT})
188      * begins in the source file at the (22,13) line,column coordinates and ends at
189      * the (22,16) coordinates and contains the String "&#047;** Javadoc comment *&#047;".
190      * <p>
191      * See also {@link org.ejen.util.arl.ArlUtil}.
192      * <p>
193      * @param doc the Document in which the nodes are to be created.
194      * @param parent the DOM node to which the new Node must be appended.
195      * @param tokensMap an <code>int</code> array specifying, for each Token
196      * kind, if this node must accepted (created), crossed (only the
197      * CDATA section is created without a parent &lt;tok...&gt; node creation)
198      * or removed (no node creation, no CDATA section).
199      * @param tokensPos if true, this Token position coordinates will be includes
200      * as attributes.
201      * @throws org.w3c.dom.DOMException DOM errors...
202      */

203     protected final void toSpecialNode(org.w3c.dom.Document JavaDoc doc,
204             org.w3c.dom.Node JavaDoc parent,
205             int[] tokensMap,
206             boolean tokensPos)
207         throws org.w3c.dom.DOMException JavaDoc {
208         if (tokensMap[kind] == ArlUtil.F_REMOVE) {
209             return;
210         }
211         if (tokensMap[kind] == ArlUtil.F_ACCEPT) {
212             org.w3c.dom.Element JavaDoc elt = doc.createElement("stok");
213
214             elt.setAttribute("ki", String.valueOf(kind));
215             if (tokensPos) {
216                 elt.setAttribute("bl", String.valueOf(beginLine));
217                 elt.setAttribute("bc", String.valueOf(beginColumn));
218                 elt.setAttribute("el", String.valueOf(endLine));
219                 elt.setAttribute("ec", String.valueOf(endColumn));
220             }
221             parent.appendChild(elt);
222             parent = elt;
223         }
224         parent.appendChild(doc.createCDATASection(image));
225     }
226     // --------------------------- New
227
}
228
Popular Tags