001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.Token
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.compile;
023:
024: /**
025: * Describes the input token stream.
026: */
027:
028: public class Token {
029:
030: /**
031: * An integer that describes the kind of this token. This numbering
032: * system is determined by JavaCCParser, and a table of these numbers is
033: * stored in the file ...Constants.java.
034: */
035: public int kind;
036:
037: /**
038: * beginLine and beginColumn describe the position of the first character
039: * of this token; endLine and endColumn describe the position of the
040: * last character of this token.
041: */
042: public int beginLine, beginColumn, endLine, endColumn;
043:
044: /**
045: * beginOffset and endOffset are useful for siphoning substrings out of
046: * the Statement so that we can recompile the substrings at upgrade time.
047: * For instance, VIEW definitions and the Restrictions on Published Tables
048: * need to be recompiled at upgrade time.
049: */
050: public int beginOffset, endOffset;
051:
052: /**
053: * The string image of the token.
054: */
055: public String image;
056:
057: /**
058: * A reference to the next regular (non-special) token from the input
059: * stream. If this is the last token from the input stream, or if the
060: * token manager has not read tokens beyond this one, this field is
061: * set to null. This is true only if this token is also a regular
062: * token. Otherwise, see below for a description of the contents of
063: * this field.
064: */
065: public Token next;
066:
067: /**
068: * This field is used to access special tokens that occur prior to this
069: * token, but after the immediately preceding regular (non-special) token.
070: * If there are no such special tokens, this field is set to null.
071: * When there are more than one such special token, this field refers
072: * to the last of these special tokens, which in turn refers to the next
073: * previous special token through its specialToken field, and so on
074: * until the first special token (whose specialToken field is null).
075: * The next fields of special tokens refer to other special tokens that
076: * immediately follow it (without an intervening regular token). If there
077: * is no such token, this field is null.
078: */
079: public Token specialToken;
080:
081: /**
082: * Returns the image.
083: */
084: public String toString() {
085: return image;
086: }
087:
088: /**
089: * Returns a new Token object, by default. However, if you want, you
090: * can create and return subclass objects based on the value of ofKind.
091: * Simply add the cases to the switch for all those special cases.
092: * For example, if you have a subclass of Token called IDToken that
093: * you want to create if ofKind is ID, simlpy add something like :
094: *
095: * case MyParserConstants.ID : return new IDToken();
096: *
097: * to the following switch statement. Then you can cast matchedToken
098: * variable to the appropriate type and use it in your lexical actions.
099: */
100: public static final Token newToken(int ofKind) {
101: switch (ofKind) {
102: default:
103: return new Token();
104: }
105: }
106:
107: }
|