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