001/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 6.0 */ 002/* JavaCCOptions:KEEP_LINE_COL=null */ 003package org.dllearner.confparser; 004 005/** 006 * This exception is thrown when parse errors are encountered. 007 * You can explicitly create objects of this exception type by 008 * calling the method generateParseException in the generated 009 * parser. 010 * 011 * You can modify this class to customize your error reporting 012 * mechanisms so long as you retain the public fields. 013 */ 014public class ParseException extends Exception { 015 016 /** 017 * The version identifier for this Serializable class. 018 * Increment only if the <i>serialized</i> form of the 019 * class changes. 020 */ 021 private static final long serialVersionUID = 1L; 022 023 /** 024 * This constructor is used by the method "generateParseException" 025 * in the generated parser. Calling this constructor generates 026 * a new object of this type with the fields "currentToken", 027 * "expectedTokenSequences", and "tokenImage" set. 028 */ 029 public ParseException(Token currentTokenVal, 030 int[][] expectedTokenSequencesVal, 031 String[] tokenImageVal 032 ) 033 { 034 super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); 035 currentToken = currentTokenVal; 036 expectedTokenSequences = expectedTokenSequencesVal; 037 tokenImage = tokenImageVal; 038 } 039 040 /** 041 * The following constructors are for use by you for whatever 042 * purpose you can think of. Constructing the exception in this 043 * manner makes the exception behave in the normal way - i.e., as 044 * documented in the class "Throwable". The fields "errorToken", 045 * "expectedTokenSequences", and "tokenImage" do not contain 046 * relevant information. The JavaCC generated code does not use 047 * these constructors. 048 */ 049 050 public ParseException() { 051 super(); 052 } 053 054 /** Constructor with message. */ 055 public ParseException(String message) { 056 super(message); 057 } 058 059 /** 060 * This is the last token that has been consumed successfully. If 061 * this object has been created due to a parse error, the token 062 * followng this token will (therefore) be the first error token. 063 */ 064 public Token currentToken; 065 066 /** 067 * Each entry in this array is an array of integers. Each array 068 * of integers represents a sequence of tokens (by their ordinal 069 * values) that is expected at this point of the parse. 070 */ 071 public int[][] expectedTokenSequences; 072 073 /** 074 * This is a reference to the "tokenImage" array of the generated 075 * parser within which the parse error occurred. This array is 076 * defined in the generated ...Constants interface. 077 */ 078 public String[] tokenImage; 079 080 /** 081 * It uses "currentToken" and "expectedTokenSequences" to generate a parse 082 * error message and returns it. If this object has been created 083 * due to a parse error, and you do not catch it (it gets thrown 084 * from the parser) the correct error message 085 * gets displayed. 086 */ 087 private static String initialise(Token currentToken, 088 int[][] expectedTokenSequences, 089 String[] tokenImage) { 090 String eol = System.getProperty("line.separator", "\n"); 091 StringBuffer expected = new StringBuffer(); 092 int maxSize = 0; 093 for (int i = 0; i < expectedTokenSequences.length; i++) { 094 if (maxSize < expectedTokenSequences[i].length) { 095 maxSize = expectedTokenSequences[i].length; 096 } 097 for (int j = 0; j < expectedTokenSequences[i].length; j++) { 098 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); 099 } 100 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { 101 expected.append("..."); 102 } 103 expected.append(eol).append(" "); 104 } 105 String retval = "Encountered \""; 106 Token tok = currentToken.next; 107 for (int i = 0; i < maxSize; i++) { 108 if (i != 0) retval += " "; 109 if (tok.kind == 0) { 110 retval += tokenImage[0]; 111 break; 112 } 113 retval += " " + tokenImage[tok.kind]; 114 retval += " \""; 115 retval += add_escapes(tok.image); 116 retval += " \""; 117 tok = tok.next; 118 } 119 retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; 120 retval += "." + eol; 121 if (expectedTokenSequences.length == 1) { 122 retval += "Was expecting:" + eol + " "; 123 } else { 124 retval += "Was expecting one of:" + eol + " "; 125 } 126 retval += expected.toString(); 127 return retval; 128 } 129 130 /** 131 * The end of line string for this machine. 132 */ 133 protected String eol = System.getProperty("line.separator", "\n"); 134 135 /** 136 * Used to convert raw characters to their escaped version 137 * when these raw version cannot be used as part of an ASCII 138 * string literal. 139 */ 140 static String add_escapes(String str) { 141 StringBuffer retval = new StringBuffer(); 142 char ch; 143 for (int i = 0; i < str.length(); i++) { 144 switch (str.charAt(i)) 145 { 146 case 0 : 147 continue; 148 case '\b': 149 retval.append("\\b"); 150 continue; 151 case '\t': 152 retval.append("\\t"); 153 continue; 154 case '\n': 155 retval.append("\\n"); 156 continue; 157 case '\f': 158 retval.append("\\f"); 159 continue; 160 case '\r': 161 retval.append("\\r"); 162 continue; 163 case '\"': 164 retval.append("\\\""); 165 continue; 166 case '\'': 167 retval.append("\\\'"); 168 continue; 169 case '\\': 170 retval.append("\\\\"); 171 continue; 172 default: 173 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 174 String s = "0000" + Integer.toString(ch, 16); 175 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 176 } else { 177 retval.append(ch); 178 } 179 continue; 180 } 181 } 182 return retval.toString(); 183 } 184 185} 186/* JavaCC - OriginalChecksum=83b39037671be2819266390c16f2c4dc (do not edit this line) */