01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.expression.ast;
05:
06: /**
07: * Describes the input token stream.
08: */
09:
10: public class Token {
11:
12: /**
13: * An integer that describes the kind of this token. This numbering system is determined by JavaCCParser, and a
14: * table of these numbers is stored in the file ...Constants.java.
15: */
16: public int kind;
17:
18: /**
19: * beginLine and beginColumn describe the position of the first character of this token; endLine and endColumn
20: * describe the position of the last character of this token.
21: */
22: public int beginLine, beginColumn, endLine, endColumn;
23:
24: /**
25: * The string image of the token.
26: */
27: public String image;
28:
29: /**
30: * A reference to the next regular (non-special) token from the input stream. If this is the last token from the
31: * input stream, or if the token manager has not read tokens beyond this one, this field is set to null. This is
32: * true only if this token is also a regular token. Otherwise, see below for a description of the contents of this
33: * field.
34: */
35: public Token next;
36:
37: /**
38: * This field is used to access special tokens that occur prior to this token, but after the immediately preceding
39: * regular (non-special) token. If there are no such special tokens, this field is set to null. When there are more
40: * than one such special token, this field refers to the last of these special tokens, which in turn refers to the
41: * next previous special token through its specialToken field, and so on until the first special token (whose
42: * specialToken field is null). The next fields of special tokens refer to other special tokens that immediately
43: * follow it (without an intervening regular token). If there is no such token, this field is null.
44: */
45: public Token specialToken;
46:
47: /**
48: * Returns the image.
49: */
50: public String toString() {
51: return image;
52: }
53:
54: /**
55: * Returns a new Token object, by default. However, if you want, you can create and return subclass objects based on
56: * the value of ofKind. Simply add the cases to the switch for all those special cases. For example, if you have a
57: * subclass of Token called IDToken that you want to create if ofKind is ID, simlpy add something like : case
58: * MyParserConstants.ID : return new IDToken(); to the following switch statement. Then you can cast matchedToken
59: * variable to the appropriate type and use it in your lexical actions.
60: */
61: public static final Token newToken(int ofKind) {
62: switch (ofKind) {
63: default:
64: return new Token();
65: }
66: }
67:
68: }
|