KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > annotation > factory > ast > Token


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.annotation.factory.ast;
23
24 /**
25  * Describes the input token stream.
26  */

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

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

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

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

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

71   public Token specialToken;
72
73   /**
74    * Returns the image.
75    */

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

93   public static final Token newToken(int ofKind)
94   {
95      switch(ofKind)
96      {
97        default : return new Token();
98      }
99   }
100
101 }
102
Popular Tags