001 /* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
002 package gate.yam.parse;
003
004 /**
005 * Describes the input token stream.
006 */
007
008 public class Token {
009
010 /**
011 * An integer that describes the kind of this token. This numbering
012 * system is determined by JavaCCParser, and a table of these numbers is
013 * stored in the file ...Constants.java.
014 */
015 public int kind;
016
017 /**
018 * beginLine and beginColumn describe the position of the first character
019 * of this token; endLine and endColumn describe the position of the
020 * last character of this token.
021 */
022 public int beginLine, beginColumn, endLine, endColumn;
023
024 /**
025 * The offsets of the token in absolute characters from the start of
026 * the document. These are not set by default, but are used by the
027 * pretty-printing translator.
028 */
029 public int startOffset = -1, endOffset = -1;
030
031 /**
032 * The string image of the token.
033 */
034 public String image;
035
036 /**
037 * A reference to the next regular (non-special) token from the input
038 * stream. If this is the last token from the input stream, or if the
039 * token manager has not read tokens beyond this one, this field is
040 * set to null. This is true only if this token is also a regular
041 * token. Otherwise, see below for a description of the contents of
042 * this field.
043 */
044 public Token next;
045
046 /**
047 * This field is used to access special tokens that occur prior to this
048 * token, but after the immediately preceding regular (non-special) token.
049 * If there are no such special tokens, this field is set to null.
050 * When there are more than one such special token, this field refers
051 * to the last of these special tokens, which in turn refers to the next
052 * previous special token through its specialToken field, and so on
053 * until the first special token (whose specialToken field is null).
054 * The next fields of special tokens refer to other special tokens that
055 * immediately follow it (without an intervening regular token). If there
056 * is no such token, this field is null.
057 */
058 public Token specialToken;
059
060 /**
061 * Returns the image.
062 */
063 public String toString()
064 {
065 return image;
066 }
067
068 /**
069 * Returns a new Token object, by default. However, if you want, you
070 * can create and return subclass objects based on the value of ofKind.
071 * Simply add the cases to the switch for all those special cases.
072 * For example, if you have a subclass of Token called IDToken that
073 * you want to create if ofKind is ID, simlpy add something like :
074 *
075 * case MyParserConstants.ID : return new IDToken();
076 *
077 * to the following switch statement. Then you can cast matchedToken
078 * variable to the appropriate type and use it in your lexical actions.
079 */
080 public static final Token newToken(int ofKind)
081 {
082 switch(ofKind)
083 {
084 default : return new Token();
085 }
086 }
087
088 /**
089 * Do two tokens point to the same place?
090 * (Two null values are considered to point to the same place.)
091 */
092 public static boolean samePlace(Token a, Token b) {
093 if(a == null || b == null) return a == b;
094 return a.samePlace(b);
095 } // samePlace(Token, Token)
096
097 /**
098 * Do two tokens point to the same place?
099 */
100 public boolean samePlace(Token other) {
101 if(other == null) return false;
102 return
103 this.beginLine == other.beginLine &&
104 this.beginColumn == other.beginColumn &&
105 this.endLine == other.endLine &&
106 this.endColumn == other.endColumn;
107 } // samePlace(Token)
108
109 } // Token
|