001/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ 002/* JavaCCOptions:KEEP_LINE_COL=null */ 003/* 004 * jDTAUS Core RI Client Container 005 * Copyright (C) 2005 Christian Schulte 006 * <cs@schulte.it> 007 * 008 * This library is free software; you can redistribute it and/or 009 * modify it under the terms of the GNU Lesser General Public 010 * License as published by the Free Software Foundation; either 011 * version 2.1 of the License, or any later version. 012 * 013 * This library is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 016 * Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with this library; if not, write to the Free Software 020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 021 * 022 * $JDTAUS: VersionParser.jj 8641 2012-09-27 06:45:17Z schulte $ 023 * 024 */ 025package org.jdtaus.core.container.ri.client.versioning; 026 027/** 028 * This exception is thrown when parse errors are encountered. 029 * You can explicitly create objects of this exception type by 030 * calling the method generateParseException in the generated 031 * parser. 032 * 033 * You can modify this class to customize your error reporting 034 * mechanisms so long as you retain the public fields. 035 */ 036public class ParseException extends Exception { 037 038 /** 039 * The version identifier for this Serializable class. 040 * Increment only if the <i>serialized</i> form of the 041 * class changes. 042 */ 043 private static final long serialVersionUID = 1L; 044 045 /** 046 * This constructor is used by the method "generateParseException" 047 * in the generated parser. Calling this constructor generates 048 * a new object of this type with the fields "currentToken", 049 * "expectedTokenSequences", and "tokenImage" set. 050 */ 051 public ParseException(Token currentTokenVal, 052 int[][] expectedTokenSequencesVal, 053 String[] tokenImageVal 054 ) 055 { 056 super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); 057 currentToken = currentTokenVal; 058 expectedTokenSequences = expectedTokenSequencesVal; 059 tokenImage = tokenImageVal; 060 } 061 062 /** 063 * The following constructors are for use by you for whatever 064 * purpose you can think of. Constructing the exception in this 065 * manner makes the exception behave in the normal way - i.e., as 066 * documented in the class "Throwable". The fields "errorToken", 067 * "expectedTokenSequences", and "tokenImage" do not contain 068 * relevant information. The JavaCC generated code does not use 069 * these constructors. 070 */ 071 072 public ParseException() { 073 super(); 074 } 075 076 /** Constructor with message. */ 077 public ParseException(String message) { 078 super(message); 079 } 080 081 082 /** 083 * This is the last token that has been consumed successfully. If 084 * this object has been created due to a parse error, the token 085 * followng this token will (therefore) be the first error token. 086 */ 087 public Token currentToken; 088 089 /** 090 * Each entry in this array is an array of integers. Each array 091 * of integers represents a sequence of tokens (by their ordinal 092 * values) that is expected at this point of the parse. 093 */ 094 public int[][] expectedTokenSequences; 095 096 /** 097 * This is a reference to the "tokenImage" array of the generated 098 * parser within which the parse error occurred. This array is 099 * defined in the generated ...Constants interface. 100 */ 101 public String[] tokenImage; 102 103 /** 104 * It uses "currentToken" and "expectedTokenSequences" to generate a parse 105 * error message and returns it. If this object has been created 106 * due to a parse error, and you do not catch it (it gets thrown 107 * from the parser) the correct error message 108 * gets displayed. 109 */ 110 private static String initialise(Token currentToken, 111 int[][] expectedTokenSequences, 112 String[] tokenImage) { 113 String eol = System.getProperty("line.separator", "\n"); 114 StringBuffer expected = new StringBuffer(); 115 int maxSize = 0; 116 for (int i = 0; i < expectedTokenSequences.length; i++) { 117 if (maxSize < expectedTokenSequences[i].length) { 118 maxSize = expectedTokenSequences[i].length; 119 } 120 for (int j = 0; j < expectedTokenSequences[i].length; j++) { 121 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); 122 } 123 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { 124 expected.append("..."); 125 } 126 expected.append(eol).append(" "); 127 } 128 String retval = "Encountered \""; 129 Token tok = currentToken.next; 130 for (int i = 0; i < maxSize; i++) { 131 if (i != 0) retval += " "; 132 if (tok.kind == 0) { 133 retval += tokenImage[0]; 134 break; 135 } 136 retval += " " + tokenImage[tok.kind]; 137 retval += " \""; 138 retval += add_escapes(tok.image); 139 retval += " \""; 140 tok = tok.next; 141 } 142 retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; 143 retval += "." + eol; 144 if (expectedTokenSequences.length == 1) { 145 retval += "Was expecting:" + eol + " "; 146 } else { 147 retval += "Was expecting one of:" + eol + " "; 148 } 149 retval += expected.toString(); 150 return retval; 151 } 152 153 /** 154 * The end of line string for this machine. 155 */ 156 protected String eol = System.getProperty("line.separator", "\n"); 157 158 /** 159 * Used to convert raw characters to their escaped version 160 * when these raw version cannot be used as part of an ASCII 161 * string literal. 162 */ 163 static String add_escapes(String str) { 164 StringBuffer retval = new StringBuffer(); 165 char ch; 166 for (int i = 0; i < str.length(); i++) { 167 switch (str.charAt(i)) 168 { 169 case 0 : 170 continue; 171 case '\b': 172 retval.append("\\b"); 173 continue; 174 case '\t': 175 retval.append("\\t"); 176 continue; 177 case '\n': 178 retval.append("\\n"); 179 continue; 180 case '\f': 181 retval.append("\\f"); 182 continue; 183 case '\r': 184 retval.append("\\r"); 185 continue; 186 case '\"': 187 retval.append("\\\""); 188 continue; 189 case '\'': 190 retval.append("\\\'"); 191 continue; 192 case '\\': 193 retval.append("\\\\"); 194 continue; 195 default: 196 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 197 String s = "0000" + Integer.toString(ch, 16); 198 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 199 } else { 200 retval.append(ch); 201 } 202 continue; 203 } 204 } 205 return retval.toString(); 206 } 207 208} 209/* JavaCC - OriginalChecksum=6ef00976d8756d87f4a98b2a0d461b9d (do not edit this line) */