001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */ 020/* JavaCCOptions: */ 021package org.dllearner.parser; 022 023/** Token Manager Error. */ 024@SuppressWarnings("all") 025public class TokenMgrError extends Error 026{ 027 028 /* 029 * Ordinals for various reasons why an Error of this type can be thrown. 030 */ 031 032 /** 033 * Lexical error occurred. 034 */ 035 static final int LEXICAL_ERROR = 0; 036 037 /** 038 * An attempt was made to create a second instance of a static token manager. 039 */ 040 static final int STATIC_LEXER_ERROR = 1; 041 042 /** 043 * Tried to change to an invalid lexical state. 044 */ 045 static final int INVALID_LEXICAL_STATE = 2; 046 047 /** 048 * Detected (and bailed out of) an infinite loop in the token manager. 049 */ 050 static final int LOOP_DETECTED = 3; 051 052 /** 053 * Indicates the reason why the exception is thrown. It will have 054 * one of the above 4 values. 055 */ 056 int errorCode; 057 058 /** 059 * Replaces unprintable characters by their escaped (or unicode escaped) 060 * equivalents in the given string 061 */ 062 protected static final String addEscapes(String str) { 063 StringBuffer retval = new StringBuffer(); 064 char ch; 065 for (int i = 0; i < str.length(); i++) { 066 switch (str.charAt(i)) 067 { 068 case 0 : 069 continue; 070 case '\b': 071 retval.append("\\b"); 072 continue; 073 case '\t': 074 retval.append("\\t"); 075 continue; 076 case '\n': 077 retval.append("\\n"); 078 continue; 079 case '\f': 080 retval.append("\\f"); 081 continue; 082 case '\r': 083 retval.append("\\r"); 084 continue; 085 case '\"': 086 retval.append("\\\""); 087 continue; 088 case '\'': 089 retval.append("\\\'"); 090 continue; 091 case '\\': 092 retval.append("\\\\"); 093 continue; 094 default: 095 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 096 String s = "0000" + Integer.toString(ch, 16); 097 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 098 } else { 099 retval.append(ch); 100 } 101 continue; 102 } 103 } 104 return retval.toString(); 105 } 106 107 /** 108 * Returns a detailed message for the Error when it is thrown by the 109 * token manager to indicate a lexical error. 110 * Parameters : 111 * EOFSeen : indicates if EOF caused the lexical error 112 * curLexState : lexical state in which this error occurred 113 * errorLine : line number when the error occurred 114 * errorColumn : column number when the error occurred 115 * errorAfter : prefix that was seen before this error occurred 116 * curchar : the offending character 117 * Note: You can customize the lexical error message by modifying this method. 118 */ 119 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 120 return("Lexical error at line " + 121 errorLine + ", column " + 122 errorColumn + ". Encountered: " + 123 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 124 "after : \"" + addEscapes(errorAfter) + "\""); 125 } 126 127 /** 128 * You can also modify the body of this method to customize your error messages. 129 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 130 * of end-users concern, so you can return something like : 131 * 132 * "Internal Error : Please file a bug report .... " 133 * 134 * from this method for such cases in the release version of your parser. 135 */ 136 public String getMessage() { 137 return super.getMessage(); 138 } 139 140 /* 141 * Constructors of various flavors follow. 142 */ 143 144 /** No arg constructor. */ 145 public TokenMgrError() { 146 } 147 148 /** Constructor with message and reason. */ 149 public TokenMgrError(String message, int reason) { 150 super(message); 151 errorCode = reason; 152 } 153 154 /** Full Constructor. */ 155 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 156 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 157 } 158} 159/* JavaCC - OriginalChecksum=520337036fd46df117e8ba0a007c282e (do not edit this line) */