KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > xpointer > parser > Token


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.xpointer.parser;
17
18 /**
19  * Describes the input token stream.
20  */

21
22 public class Token {
23
24     /**
25      * An integer that describes the kind of this token. This numbering
26      * system is determined by JavaCCParser, and a table of these numbers is
27      * stored in the file ...Constants.java.
28      */

29     public int kind;
30
31     /**
32      * beginLine and beginColumn describe the position of the first character
33      * of this token; endLine and endColumn describe the position of the
34      * last character of this token.
35      */

36     public int beginLine, beginColumn, endLine, endColumn;
37
38     /**
39      * The string image of the token.
40      */

41     public String JavaDoc image;
42
43     /**
44      * A reference to the next regular (non-special) token from the input
45      * stream. If this is the last token from the input stream, or if the
46      * token manager has not read tokens beyond this one, this field is
47      * set to null. This is true only if this token is also a regular
48      * token. Otherwise, see below for a description of the contents of
49      * this field.
50      */

51     public Token next;
52
53     /**
54      * This field is used to access special tokens that occur prior to this
55      * token, but after the immediately preceding regular (non-special) token.
56      * If there are no such special tokens, this field is set to null.
57      * When there are more than one such special token, this field refers
58      * to the last of these special tokens, which in turn refers to the next
59      * previous special token through its specialToken field, and so on
60      * until the first special token (whose specialToken field is null).
61      * The next fields of special tokens refer to other special tokens that
62      * immediately follow it (without an intervening regular token). If there
63      * is no such token, this field is null.
64      */

65     public Token specialToken;
66
67     /**
68      * Returns the image.
69      */

70     public String JavaDoc toString() {
71         return image;
72     }
73
74     /**
75      * Returns a new Token object, by default. However, if you want, you
76      * can create and return subclass objects based on the value of ofKind.
77      * Simply add the cases to the switch for all those special cases.
78      * For example, if you have a subclass of Token called IDToken that
79      * you want to create if ofKind is ID, simlpy add something like :
80      *
81      * case MyParserConstants.ID : return new IDToken();
82      *
83      * to the following switch statement. Then you can cast matchedToken
84      * variable to the appropriate type and use it in your lexical actions.
85      */

86     public static final Token newToken(int ofKind) {
87         switch (ofKind) {
88             default :
89                 return new Token();
90         }
91     }
92
93 }
94
Popular Tags