001    /* Generated By:JavaCC: Do not edit this line. Token.java Version 4.1 */
002    /* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null */
003    /*
004     *   Copyright (c) 2009 The JOMC Project
005     *   Copyright (c) 2005 Christian Schulte <cs@jomc.org>
006     *   All rights reserved.
007     *
008     *   Redistribution and use in source and binary forms, with or without
009     *   modification, are permitted provided that the following conditions
010     *   are met:
011     *
012     *     o Redistributions of source code must retain the above copyright
013     *       notice, this list of conditions and the following disclaimer.
014     *
015     *     o Redistributions in binary form must reproduce the above copyright
016     *       notice, this list of conditions and the following disclaimer in
017     *       the documentation and/or other materials provided with the
018     *       distribution.
019     *
020     *   THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
021     *   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
022     *   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
023     *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
024     *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025     *   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026     *   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
027     *   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
028     *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
029     *   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
030     *   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031     *
032     *   $Id: VersionParser.jj 402 2009-08-25 13:51:07Z schulte2005 $
033     *
034     */
035    package org.jomc.util;
036    
037    /**
038     * Describes the input token stream.
039     */
040    
041    public class Token {
042    
043      /**
044       * An integer that describes the kind of this token.  This numbering
045       * system is determined by JavaCCParser, and a table of these numbers is
046       * stored in the file ...Constants.java.
047       */
048      public int kind;
049    
050      /** The line number of the first character of this Token. */
051      public int beginLine;
052      /** The column number of the first character of this Token. */
053      public int beginColumn;
054      /** The line number of the last character of this Token. */
055      public int endLine;
056      /** The column number of the last character of this Token. */
057      public int endColumn;
058    
059      /**
060       * The string image of the token.
061       */
062      public String image;
063    
064      /**
065       * A reference to the next regular (non-special) token from the input
066       * stream.  If this is the last token from the input stream, or if the
067       * token manager has not read tokens beyond this one, this field is
068       * set to null.  This is true only if this token is also a regular
069       * token.  Otherwise, see below for a description of the contents of
070       * this field.
071       */
072      public Token next;
073    
074      /**
075       * This field is used to access special tokens that occur prior to this
076       * token, but after the immediately preceding regular (non-special) token.
077       * If there are no such special tokens, this field is set to null.
078       * When there are more than one such special token, this field refers
079       * to the last of these special tokens, which in turn refers to the next
080       * previous special token through its specialToken field, and so on
081       * until the first special token (whose specialToken field is null).
082       * The next fields of special tokens refer to other special tokens that
083       * immediately follow it (without an intervening regular token).  If there
084       * is no such token, this field is null.
085       */
086      public Token specialToken;
087    
088      /**
089       * An optional attribute value of the Token.
090       * Tokens which are not used as syntactic sugar will often contain
091       * meaningful values that will be used later on by the compiler or
092       * interpreter. This attribute value is often different from the image.
093       * Any subclass of Token that actually wants to return a non-null value can
094       * override this method as appropriate.
095       */
096      public Object getValue() {
097        return null;
098      }
099    
100      /**
101       * No-argument constructor
102       */
103      public Token() {}
104    
105      /**
106       * Constructs a new token for the specified Image.
107       */
108      public Token(int kind)
109      {
110         this(kind, null);
111      }
112    
113      /**
114       * Constructs a new token for the specified Image and Kind.
115       */
116      public Token(int kind, String image)
117      {
118         this.kind = kind;
119         this.image = image;
120      }
121    
122      /**
123       * Returns the image.
124       */
125      public String toString()
126      {
127         return image;
128      }
129    
130      /**
131       * Returns a new Token object, by default. However, if you want, you
132       * can create and return subclass objects based on the value of ofKind.
133       * Simply add the cases to the switch for all those special cases.
134       * For example, if you have a subclass of Token called IDToken that
135       * you want to create if ofKind is ID, simply add something like :
136       *
137       *    case MyParserConstants.ID : return new IDToken(ofKind, image);
138       *
139       * to the following switch statement. Then you can cast matchedToken
140       * variable to the appropriate type and use sit in your lexical actions.
141       */
142      public static Token newToken(int ofKind, String image)
143      {
144         switch(ofKind)
145         {
146           default : return new Token(ofKind, image);
147         }
148      }
149    
150      public static Token newToken(int ofKind)
151      {
152         return newToken(ofKind, null);
153      }
154    
155    }
156    /* JavaCC - OriginalChecksum=3ff4eb1ad7d0cced2f2c3159c061fa63 (do not edit this line) */