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