| 1 | /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ |
| 2 | /* JavaCCOptions:KEEP_LINE_COL=null */ |
| 3 | /* |
| 4 | * jDTAUS Core RI Client Container |
| 5 | * Copyright (C) 2005 Christian Schulte |
| 6 | * <cs@schulte.it> |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | * |
| 22 | * $JDTAUS: VersionParser.jj 8641 2012-09-27 06:45:17Z schulte $ |
| 23 | * |
| 24 | */ |
| 25 | package org.jdtaus.core.container.ri.client.versioning; |
| 26 | |
| 27 | /** |
| 28 | * This exception is thrown when parse errors are encountered. |
| 29 | * You can explicitly create objects of this exception type by |
| 30 | * calling the method generateParseException in the generated |
| 31 | * parser. |
| 32 | * |
| 33 | * You can modify this class to customize your error reporting |
| 34 | * mechanisms so long as you retain the public fields. |
| 35 | */ |
| 36 | public class ParseException extends Exception { |
| 37 | |
| 38 | /** |
| 39 | * The version identifier for this Serializable class. |
| 40 | * Increment only if the <i>serialized</i> form of the |
| 41 | * class changes. |
| 42 | */ |
| 43 | private static final long serialVersionUID = 1L; |
| 44 | |
| 45 | /** |
| 46 | * This constructor is used by the method "generateParseException" |
| 47 | * in the generated parser. Calling this constructor generates |
| 48 | * a new object of this type with the fields "currentToken", |
| 49 | * "expectedTokenSequences", and "tokenImage" set. |
| 50 | */ |
| 51 | public ParseException(Token currentTokenVal, |
| 52 | int[][] expectedTokenSequencesVal, |
| 53 | String[] tokenImageVal |
| 54 | ) |
| 55 | { |
| 56 | super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); |
| 57 | currentToken = currentTokenVal; |
| 58 | expectedTokenSequences = expectedTokenSequencesVal; |
| 59 | tokenImage = tokenImageVal; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * The following constructors are for use by you for whatever |
| 64 | * purpose you can think of. Constructing the exception in this |
| 65 | * manner makes the exception behave in the normal way - i.e., as |
| 66 | * documented in the class "Throwable". The fields "errorToken", |
| 67 | * "expectedTokenSequences", and "tokenImage" do not contain |
| 68 | * relevant information. The JavaCC generated code does not use |
| 69 | * these constructors. |
| 70 | */ |
| 71 | |
| 72 | public ParseException() { |
| 73 | super(); |
| 74 | } |
| 75 | |
| 76 | /** Constructor with message. */ |
| 77 | public ParseException(String message) { |
| 78 | super(message); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /** |
| 83 | * This is the last token that has been consumed successfully. If |
| 84 | * this object has been created due to a parse error, the token |
| 85 | * followng this token will (therefore) be the first error token. |
| 86 | */ |
| 87 | public Token currentToken; |
| 88 | |
| 89 | /** |
| 90 | * Each entry in this array is an array of integers. Each array |
| 91 | * of integers represents a sequence of tokens (by their ordinal |
| 92 | * values) that is expected at this point of the parse. |
| 93 | */ |
| 94 | public int[][] expectedTokenSequences; |
| 95 | |
| 96 | /** |
| 97 | * This is a reference to the "tokenImage" array of the generated |
| 98 | * parser within which the parse error occurred. This array is |
| 99 | * 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=f7a9c139fca4beca50e52b80ad753e31 (do not edit this line) */ |