001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: */
022:
023: package org.enhydra.spi.conf.util;
024:
025: /**
026: * Describes the input token stream.
027: */
028:
029: public class Token {
030:
031: /**
032: * An integer that describes the kind of this token. This numbering
033: * system is determined by JavaCCParser, and a table of these numbers is
034: * stored in the file ...Constants.java.
035: */
036: public int kind;
037:
038: /**
039: * beginLine and beginColumn describe the position of the first character
040: * of this token; endLine and endColumn describe the position of the
041: * last character of this token.
042: */
043: public int beginLine, beginColumn, endLine, endColumn;
044:
045: /**
046: * The string image of the token.
047: */
048: public String image;
049:
050: /**
051: * A reference to the next regular (non-special) token from the input
052: * stream. If this is the last token from the input stream, or if the
053: * token manager has not read tokens beyond this one, this field is
054: * set to null. This is true only if this token is also a regular
055: * token. Otherwise, see below for a description of the contents of
056: * this field.
057: */
058: public Token next;
059:
060: /**
061: * This field is used to access special tokens that occur prior to this
062: * token, but after the immediately preceding regular (non-special) token.
063: * If there are no such special tokens, this field is set to null.
064: * When there are more than one such special token, this field refers
065: * to the last of these special tokens, which in turn refers to the next
066: * previous special token through its specialToken field, and so on
067: * until the first special token (whose specialToken field is null).
068: * The next fields of special tokens refer to other special tokens that
069: * immediately follow it (without an intervening regular token). If there
070: * is no such token, this field is null.
071: */
072: public Token specialToken;
073:
074: /**
075: * Returns the image.
076: * @return The image.
077: */
078: public String toString() {
079: return image;
080: }
081:
082: /**
083: * Returns a new Token object, by default. However, if you want, you
084: * can create and return subclass objects based on the value of ofKind.
085: * Simply add the cases to the switch for all those special cases.
086: * For example, if you have a subclass of Token called IDToken that
087: * you want to create if ofKind is ID, simlpy add something like :
088: *
089: * case MyParserConstants.ID : return new IDToken();
090: *
091: * to the following switch statement. Then you can cast matchedToken
092: * variable to the appropriate type and use it in your lexical actions.
093: *
094: * @param ofKind Type of objects to be returned.
095: * @return New token subclass objects based on the value of ofKind.
096: */
097: public static final Token newToken(int ofKind) {
098: switch (ofKind) {
099: default:
100: return new Token();
101: }
102: }
103:
104: }
|