KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > spi > conf > util > Token


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22
23 package org.enhydra.spi.conf.util;
24
25 /**
26  * Describes the input token stream.
27  */

28
29 public class Token {
30
31   /**
32    * An integer that describes the kind of this token. This numbering
33    * system is determined by JavaCCParser, and a table of these numbers is
34    * stored in the file ...Constants.java.
35    */

36   public int kind;
37
38   /**
39    * beginLine and beginColumn describe the position of the first character
40    * of this token; endLine and endColumn describe the position of the
41    * last character of this token.
42    */

43   public int beginLine, beginColumn, endLine, endColumn;
44
45   /**
46    * The string image of the token.
47    */

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

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

72   public Token specialToken;
73
74   /**
75    * Returns the image.
76    * @return The image.
77    */

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

98   public static final Token newToken(int ofKind)
99   {
100      switch(ofKind)
101      {
102        default : return new Token();
103      }
104   }
105
106 }
107
Popular Tags