001/* 002 * Units of Measurement Reference Implementation 003 * Copyright (c) 2005-2018, Jean-Marie Dautelle, Werner Keil, Otavio Santana. 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-385, Indriya nor the names of their 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 tech.units.indriya.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 @SuppressWarnings("unused") 070private int errorCode; 071 072 /** 073 * Replaces unprintable characters by their escaped (or unicode escaped) equivalents in the given string 074 */ 075 protected static String addEscapes(String str) { 076 StringBuilder retval = new StringBuilder(); 077 char ch; 078 for (int i = 0; i < str.length(); i++) { 079 switch (str.charAt(i)) { 080 case 0: 081 continue; 082 case '\b': 083 retval.append("\\b"); 084 continue; 085 case '\t': 086 retval.append("\\t"); 087 continue; 088 case '\n': 089 retval.append("\\n"); 090 continue; 091 case '\f': 092 retval.append("\\f"); 093 continue; 094 case '\r': 095 retval.append("\\r"); 096 continue; 097 case '\"': 098 retval.append("\\\""); 099 continue; 100 case '\'': 101 retval.append("\\\'"); 102 continue; 103 case '\\': 104 retval.append("\\\\"); 105 continue; 106 default: 107 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 108 String s = "0000" + Integer.toString(ch, 16); 109 retval.append("\\u").append(s.substring(s.length() - 4, s.length())); 110 } else { 111 retval.append(ch); 112 } 113 } 114 } 115 return retval.toString(); 116 } 117 118 /** 119 * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error. Parameters : EOFSeen : indicates if 120 * EOF caused the lexical error curLexState : lexical state in which this error occurred errorLine : line number when the error occurred errorColumn 121 * : column number when the error occurred errorAfter : prefix that was seen before this error occurred curchar : the offending character Note: You 122 * can customize the lexical error message by modifying this method. 123 */ 124 protected static String lexicalError(boolean EOFSeen, int errorLine, int errorColumn, String errorAfter, char curChar) { 125 return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " 126 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \"" 127 + addEscapes(errorAfter) + "\""); 128 } 129 130 /** 131 * 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 132 * not of end-users concern, so you can return something like : 133 * 134 * "Internal Error : Please file a bug report .... " 135 * 136 * from this method for such cases in the release version of your parser. 137 */ 138 public String getMessage() { 139 return super.getMessage(); 140 } 141 142 /* 143 * Constructors of various flavors follow. 144 */ 145 146 /** No arg constructor. */ 147 public TokenMgrError() { 148 } 149 150 /** Constructor with message and reason. */ 151 public TokenMgrError(String message, int reason) { 152 super(message); 153 errorCode = reason; 154 } 155 156 /** Full Constructor. */ 157 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 158 this(lexicalError(EOFSeen, errorLine, errorColumn, errorAfter, curChar), reason); 159 } 160} 161/* 162 * JavaCC - OriginalChecksum=8a6e5be586cca28053ad55584e013006 (do not edit this 163 * line) 164 */