001/* 002 * Units of Measurement Implementation for Java SE 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, 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 tec.uom.se.internal.format; 033 034/** Token Manager Error. */ 035public class TokenMgrError extends Error { 036 037 /** 038 * The Serialization identifier for this class. Increment only if the <i>serialized</i> form of the class changes. 039 */ 040 private static final long serialVersionUID = -3348968864772188432L; 041 042 /* 043 * Ordinals for various reasons why an Error of this type can be thrown. 044 */ 045 046 /** 047 * Lexical error occurred. 048 */ 049 static final int LEXICAL_ERROR = 0; 050 051 /** 052 * An attempt was made to create a second instance of a static token manager. 053 */ 054 static final int STATIC_LEXER_ERROR = 1; 055 056 /** 057 * Tried to change to an invalid lexical state. 058 */ 059 static final int INVALID_LEXICAL_STATE = 2; 060 061 /** 062 * Detected (and bailed out of) an infinite loop in the token manager. 063 */ 064 static final int LOOP_DETECTED = 3; 065 066 /** 067 * Indicates the reason why the exception is thrown. It will have one of the above 4 values. 068 */ 069 int errorCode; 070 071 /** 072 * Replaces unprintable characters by their escaped (or unicode escaped) equivalents in the given string 073 */ 074 protected static String addEscapes(String str) { 075 StringBuilder retval = new StringBuilder(); 076 char ch; 077 for (int i = 0; i < str.length(); i++) { 078 switch (str.charAt(i)) { 079 case 0: 080 continue; 081 case '\b': 082 retval.append("\\b"); 083 continue; 084 case '\t': 085 retval.append("\\t"); 086 continue; 087 case '\n': 088 retval.append("\\n"); 089 continue; 090 case '\f': 091 retval.append("\\f"); 092 continue; 093 case '\r': 094 retval.append("\\r"); 095 continue; 096 case '\"': 097 retval.append("\\\""); 098 continue; 099 case '\'': 100 retval.append("\\\'"); 101 continue; 102 case '\\': 103 retval.append("\\\\"); 104 continue; 105 default: 106 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 107 String s = "0000" + Integer.toString(ch, 16); 108 retval.append("\\u").append(s.substring(s.length() - 4, s.length())); 109 } else { 110 retval.append(ch); 111 } 112 } 113 } 114 return retval.toString(); 115 } 116 117 /** 118 * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error. Parameters : EOFSeen : indicates if 119 * EOF caused the lexical error curLexState : lexical state in which this error occurred errorLine : line number when the error occurred errorColumn 120 * : column number when the error occurred errorAfter : prefix that was seen before this error occurred curchar : the offending character Note: You 121 * can customize the lexical error message by modifying this method. 122 */ 123 protected static String LexicalError(boolean EOFSeen, int errorLine, int errorColumn, String errorAfter, char curChar) { 124 return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " 125 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \"" 126 + addEscapes(errorAfter) + "\""); 127 } 128 129 /** 130 * You can also modify the body of this method to customize your error messages. For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are 131 * not of end-users concern, so you can return something like : 132 * 133 * "Internal Error : Please file a bug report .... " 134 * 135 * from this method for such cases in the release version of your parser. 136 */ 137 public String getMessage() { 138 return super.getMessage(); 139 } 140 141 /* 142 * Constructors of various flavors follow. 143 */ 144 145 /** No arg constructor. */ 146 public TokenMgrError() { 147 } 148 149 /** Constructor with message and reason. */ 150 public TokenMgrError(String message, int reason) { 151 super(message); 152 errorCode = reason; 153 } 154 155 /** Full Constructor. */ 156 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 157 this(LexicalError(EOFSeen, errorLine, errorColumn, errorAfter, curChar), reason); 158 } 159} 160/* 161 * JavaCC - OriginalChecksum=8a6e5be586cca28053ad55584e013006 (do not edit this 162 * line) 163 */