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. ParseException.java Version 4.1 */ 020/* JavaCCOptions:KEEP_LINE_COL=null */ 021package org.dllearner.parser; 022 023/** 024 * This exception is thrown when parse errors are encountered. 025 * You can explicitly create objects of this exception type by 026 * calling the method generateParseException in the generated 027 * parser. 028 * 029 * You can modify this class to customize your error reporting 030 * mechanisms so long as you retain the public fields. 031 */ 032@SuppressWarnings("all") 033public class ParseException extends Exception { 034 035 /** 036 * This constructor is used by the method "generateParseException" 037 * in the generated parser. Calling this constructor generates 038 * a new object of this type with the fields "currentToken", 039 * "expectedTokenSequences", and "tokenImage" set. The boolean 040 * flag "specialConstructor" is also set to true to indicate that 041 * this constructor was used to create this object. 042 * This constructor calls its super class with the empty string 043 * to force the "toString" method of parent class "Throwable" to 044 * print the error message in the form: 045 * ParseException: <result of getMessage> 046 */ 047 public ParseException(Token currentTokenVal, 048 int[][] expectedTokenSequencesVal, 049 String[] tokenImageVal 050 ) 051 { 052 super(""); 053 specialConstructor = true; 054 currentToken = currentTokenVal; 055 expectedTokenSequences = expectedTokenSequencesVal; 056 tokenImage = tokenImageVal; 057 } 058 059 /** 060 * The following constructors are for use by you for whatever 061 * purpose you can think of. Constructing the exception in this 062 * manner makes the exception behave in the normal way - i.e., as 063 * documented in the class "Throwable". The fields "errorToken", 064 * "expectedTokenSequences", and "tokenImage" do not contain 065 * relevant information. The JavaCC generated code does not use 066 * these constructors. 067 */ 068 069 public ParseException() { 070 super(); 071 specialConstructor = false; 072 } 073 074 /** Constructor with message. */ 075 public ParseException(String message) { 076 super(message); 077 specialConstructor = false; 078 } 079 080 /** 081 * This variable determines which constructor was used to create 082 * this object and thereby affects the semantics of the 083 * "getMessage" method (see below). 084 */ 085 protected boolean specialConstructor; 086 087 /** 088 * This is the last token that has been consumed successfully. If 089 * this object has been created due to a parse error, the token 090 * followng this token will (therefore) be the first error token. 091 */ 092 public Token currentToken; 093 094 /** 095 * Each entry in this array is an array of integers. Each array 096 * of integers represents a sequence of tokens (by their ordinal 097 * values) that is expected at this point of the parse. 098 */ 099 public int[][] expectedTokenSequences; 100 101 /** 102 * This is a reference to the "tokenImage" array of the generated 103 * parser within which the parse error occurred. This array is 104 * defined in the generated ...Constants interface. 105 */ 106 public String[] tokenImage; 107 108 /** 109 * This method has the standard behavior when this object has been 110 * created using the standard constructors. Otherwise, it uses 111 * "currentToken" and "expectedTokenSequences" to generate a parse 112 * error message and returns it. If this object has been created 113 * due to a parse error, and you do not catch it (it gets thrown 114 * from the parser), then this method is called during the printing 115 * of the final stack trace, and hence the correct error message 116 * gets displayed. 117 */ 118 public String getMessage() { 119 if (!specialConstructor) { 120 return super.getMessage(); 121 } 122 StringBuffer expected = new StringBuffer(); 123 int maxSize = 0; 124 for (int i = 0; i < expectedTokenSequences.length; i++) { 125 if (maxSize < expectedTokenSequences[i].length) { 126 maxSize = expectedTokenSequences[i].length; 127 } 128 for (int j = 0; j < expectedTokenSequences[i].length; j++) { 129 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); 130 } 131 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { 132 expected.append("..."); 133 } 134 expected.append(eol).append(" "); 135 } 136 String retval = "Encountered \""; 137 Token tok = currentToken.next; 138 for (int i = 0; i < maxSize; i++) { 139 if (i != 0) retval += " "; 140 if (tok.kind == 0) { 141 retval += tokenImage[0]; 142 break; 143 } 144 retval += " " + tokenImage[tok.kind]; 145 retval += " \""; 146 retval += add_escapes(tok.image); 147 retval += " \""; 148 tok = tok.next; 149 } 150 retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; 151 retval += "." + eol; 152 if (expectedTokenSequences.length == 1) { 153 retval += "Was expecting:" + eol + " "; 154 } else { 155 retval += "Was expecting one of:" + eol + " "; 156 } 157 retval += expected.toString(); 158 return retval; 159 } 160 161 /** 162 * The end of line string for this machine. 163 */ 164 protected String eol = System.getProperty("line.separator", "\n"); 165 166 /** 167 * Used to convert raw characters to their escaped version 168 * when these raw version cannot be used as part of an ASCII 169 * string literal. 170 */ 171 protected String add_escapes(String str) { 172 StringBuffer retval = new StringBuffer(); 173 char ch; 174 for (int i = 0; i < str.length(); i++) { 175 switch (str.charAt(i)) 176 { 177 case 0 : 178 continue; 179 case '\b': 180 retval.append("\\b"); 181 continue; 182 case '\t': 183 retval.append("\\t"); 184 continue; 185 case '\n': 186 retval.append("\\n"); 187 continue; 188 case '\f': 189 retval.append("\\f"); 190 continue; 191 case '\r': 192 retval.append("\\r"); 193 continue; 194 case '\"': 195 retval.append("\\\""); 196 continue; 197 case '\'': 198 retval.append("\\\'"); 199 continue; 200 case '\\': 201 retval.append("\\\\"); 202 continue; 203 default: 204 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 205 String s = "0000" + Integer.toString(ch, 16); 206 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 207 } else { 208 retval.append(ch); 209 } 210 continue; 211 } 212 } 213 return retval.toString(); 214 } 215 216} 217/* JavaCC - OriginalChecksum=635b36f1d3290cdbc6b59e8752e3623d (do not edit this line) */