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