001/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ 002/* JavaCCOptions: */ 003/* 004 * Copyright (C) 2005 Christian Schulte <cs@schulte.it> 005 * All rights reserved. 006 * 007 * Redistribution and use in source and binary forms, with or without 008 * modification, are permitted provided that the following conditions 009 * are met: 010 * 011 * o Redistributions of source code must retain the above copyright 012 * notice, this list of conditions and the following disclaimer. 013 * 014 * o Redistributions in binary form must reproduce the above copyright 015 * notice, this list of conditions and the following disclaimer in 016 * the documentation and/or other materials provided with the 017 * distribution. 018 * 019 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 020 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 021 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 022 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 023 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 024 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 028 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 * 030 * $JOMC: VersionParser.jj 5091 2016-04-04 15:40:17Z schulte $ 031 * 032 */ 033package org.jomc.util; 034 035/** Token Manager Error. */ 036public class TokenMgrError extends Error 037{ 038 039 /** 040 * The version identifier for this Serializable class. 041 * Increment only if the <i>serialized</i> form of the 042 * class changes. 043 */ 044 private static final long serialVersionUID = 1L; 045 046 /* 047 * Ordinals for various reasons why an Error of this type can be thrown. 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 final String addEscapes(String str) { 081 StringBuffer retval = new StringBuffer(); 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" + s.substring(s.length() - 4, s.length())); 116 } else { 117 retval.append(ch); 118 } 119 continue; 120 } 121 } 122 return retval.toString(); 123 } 124 125 /** 126 * Returns a detailed message for the Error when it is thrown by the 127 * token manager to indicate a lexical error. 128 * Parameters : 129 * EOFSeen : indicates if EOF caused the lexical error 130 * curLexState : lexical state in which this error occurred 131 * errorLine : line number when the error occurred 132 * errorColumn : column number when the error occurred 133 * errorAfter : prefix that was seen before this error occurred 134 * curchar : the offending character 135 * Note: You can customize the lexical error message by modifying this method. 136 */ 137 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 138 return("Lexical error at line " + 139 errorLine + ", column " + 140 errorColumn + ". Encountered: " + 141 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 142 "after : \"" + addEscapes(errorAfter) + "\""); 143 } 144 145 /** 146 * You can also modify the body of this method to customize your error messages. 147 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 148 * of end-users concern, so you can return something like : 149 * 150 * "Internal Error : Please file a bug report .... " 151 * 152 * from this method for such cases in the release version of your parser. 153 */ 154 public String getMessage() { 155 return super.getMessage(); 156 } 157 158 /* 159 * Constructors of various flavors follow. 160 */ 161 162 /** No arg constructor. */ 163 public TokenMgrError() { 164 } 165 166 /** Constructor with message and reason. */ 167 public TokenMgrError(String message, int reason) { 168 super(message); 169 errorCode = reason; 170 } 171 172 /** Full Constructor. */ 173 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 174 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 175 } 176} 177/* JavaCC - OriginalChecksum=a6f2f136a5d31794db778bffb595299e (do not edit this line) */