001/** 002 * Unit-API - Units of Measurement API for Java 003 * Copyright (c) 2005-2014, 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, 008 * are permitted provided that the following conditions are met: 009 * 010 * 1. Redistributions of source code must retain the above copyright notice, 011 * this list of conditions and the following disclaimer. 012 * 013 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions 014 * and the following disclaimer in the documentation and/or other materials provided with the distribution. 015 * 016 * 3. Neither the name of JSR-363 nor the names of its contributors may be used to endorse or promote products 017 * derived from this software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 021 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ 031/* JavaCCOptions: */ 032package systems.uom.ucum.internal.format; 033 034/** Token Manager Error. */ 035public class TokenMgrError extends Error 036{ 037 038 /** 039 * The Serialization identifier for this class. 040 * Increment only if the <i>serialized</i> form of the 041 * class changes. 042 */ 043 private static final long serialVersionUID = -3348968864772188432L; 044 045 /* 046 * Ordinals for various reasons why an Error of this type can be thrown. 047 */ 048 049 050 /** 051 * Lexical error occurred. 052 */ 053 static final int LEXICAL_ERROR = 0; 054 055 /** 056 * An attempt was made to create a second instance of a static token manager. 057 */ 058 static final int STATIC_LEXER_ERROR = 1; 059 060 /** 061 * Tried to change to an invalid lexical state. 062 */ 063 static final int INVALID_LEXICAL_STATE = 2; 064 065 /** 066 * Detected (and bailed out of) an infinite loop in the token manager. 067 */ 068 static final int LOOP_DETECTED = 3; 069 070 /** 071 * Indicates the reason why the exception is thrown. It will have 072 * one of the above 4 values. 073 */ 074 int errorCode; 075 076 /** 077 * Replaces unprintable characters by their escaped (or unicode escaped) 078 * equivalents in the given string 079 */ 080 protected static String addEscapes(String str) { 081 StringBuilder retval = new StringBuilder(); 082 char ch; 083 for (int i = 0; i < str.length(); i++) { 084 switch (str.charAt(i)) 085 { 086 case 0 : 087 continue; 088 case '\b': 089 retval.append("\\b"); 090 continue; 091 case '\t': 092 retval.append("\\t"); 093 continue; 094 case '\n': 095 retval.append("\\n"); 096 continue; 097 case '\f': 098 retval.append("\\f"); 099 continue; 100 case '\r': 101 retval.append("\\r"); 102 continue; 103 case '\"': 104 retval.append("\\\""); 105 continue; 106 case '\'': 107 retval.append("\\\'"); 108 continue; 109 case '\\': 110 retval.append("\\\\"); 111 continue; 112 default: 113 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 114 String s = "0000" + Integer.toString(ch, 16); 115 retval.append("\\u").append(s.substring(s.length() - 4, s.length())); 116 } else { 117 retval.append(ch); 118 } 119 } 120 } 121 return retval.toString(); 122 } 123 124 /** 125 * Returns a detailed message for the Error when it is thrown by the 126 * token manager to indicate a lexical error. 127 * Parameters : 128 * EOFSeen : indicates if EOF caused the lexical error 129 * curLexState : lexical state in which this error occurred 130 * errorLine : line number when the error occurred 131 * errorColumn : column number when the error occurred 132 * errorAfter : prefix that was seen before this error occurred 133 * curchar : the offending character 134 * Note: You can customize the lexical error message by modifying this method. 135 */ 136 protected static String LexicalError(boolean EOFSeen, int errorLine, int errorColumn, String errorAfter, char curChar) { 137 return("Lexical error at line " + 138 errorLine + ", column " + 139 errorColumn + ". Encountered: " + 140 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 141 "after : \"" + addEscapes(errorAfter) + "\""); 142 } 143 144 /** 145 * You can also modify the body of this method to customize your error messages. 146 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 147 * of end-users concern, so you can return something like : 148 * 149 * "Internal Error : Please file a bug report .... " 150 * 151 * from this method for such cases in the release version of your parser. 152 */ 153 public String getMessage() { 154 return super.getMessage(); 155 } 156 157 /* 158 * Constructors of various flavors follow. 159 */ 160 161 /** No arg constructor. */ 162 public TokenMgrError() { 163 } 164 165 /** Constructor with message and reason. */ 166 public TokenMgrError(String message, int reason) { 167 super(message); 168 errorCode = reason; 169 } 170 171 /** Full Constructor. */ 172 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 173 this(LexicalError(EOFSeen, errorLine, errorColumn, errorAfter, curChar), reason); 174 } 175} 176/* JavaCC - OriginalChecksum=8a6e5be586cca28053ad55584e013006 (do not edit this line) */