001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010: /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 0.7pre6 */
011: package de.uka.ilkd.key.casetool.together.patterns.HelperClasses.MyParser;
012:
013: /**
014: * This exception is thrown when parse errors are encountered.
015: * You can explicitly create objects of this exception type by
016: * calling the method generateParseException in the generated
017: * parser.
018: *
019: * You can modify this class to customize your error reporting
020: * mechanisms so long as you retain the public fields.
021: */
022: public class ParseException extends Exception {
023:
024: /**
025: * This constructor is used by the method "generateParseException"
026: * in the generated parser. Calling this constructor generates
027: * a new object of this type with the fields "currentToken",
028: * "expectedTokenSequences", and "tokenImage" set. The boolean
029: * flag "specialConstructor" is also set to true to indicate that
030: * this constructor was used to create this object.
031: * This constructor calls its super class with the empty string
032: * to force the "toString" method of parent class "Throwable" to
033: * print the error message in the form:
034: * ParseException: <result of getMessage>
035: */
036: public ParseException(Token currentTokenVal,
037: int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
038: super ("");
039: specialConstructor = true;
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: specialConstructor = false;
058: }
059:
060: public ParseException(String message) {
061: super (message);
062: specialConstructor = false;
063: }
064:
065: /**
066: * This variable determines which constructor was used to create
067: * this object and thereby affects the semantics of the
068: * "getMessage" method (see below).
069: */
070: protected boolean specialConstructor;
071:
072: /**
073: * This is the last token that has been consumed successfully. If
074: * this object has been created due to a parse error, the token
075: * followng this token will (therefore) be the first error token.
076: */
077: public Token currentToken;
078:
079: /**
080: * Each entry in this array is an array of integers. Each array
081: * of integers represents a sequence of tokens (by their ordinal
082: * values) that is expected at this point of the parse.
083: */
084: public int[][] expectedTokenSequences;
085:
086: /**
087: * This is a reference to the "tokenImage" array of the generated
088: * parser within which the parse error occurred. This array is
089: * defined in the generated ...Constants interface.
090: */
091: public String[] tokenImage;
092:
093: /**
094: * This method has the standard behavior when this object has been
095: * created using the standard constructors. Otherwise, it uses
096: * "currentToken" and "expectedTokenSequences" to generate a parse
097: * error message and returns it. If this object has been created
098: * due to a parse error, and you do not catch it (it gets thrown
099: * from the parser), then this method is called during the printing
100: * of the final stack trace, and hence the correct error message
101: * gets displayed.
102: */
103: public String getMessage() {
104: if (!specialConstructor) {
105: return super .getMessage();
106: }
107: String expected = "";
108: int maxSize = 0;
109: for (int i = 0; i < expectedTokenSequences.length; i++) {
110: if (maxSize < expectedTokenSequences[i].length) {
111: maxSize = expectedTokenSequences[i].length;
112: }
113: for (int j = 0; j < expectedTokenSequences[i].length; j++) {
114: expected += tokenImage[expectedTokenSequences[i][j]]
115: + " ";
116: }
117: if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
118: expected += "...";
119: }
120: expected += eol + " ";
121: }
122: String retval = "Encountered \"";
123: Token tok = currentToken.next;
124: for (int i = 0; i < maxSize; i++) {
125: if (i != 0)
126: retval += " ";
127: if (tok.kind == 0) {
128: retval += tokenImage[0];
129: break;
130: }
131: retval += add_escapes(tok.image);
132: tok = tok.next;
133: }
134: retval += "\" at line " + currentToken.next.beginLine
135: + ", column " + currentToken.next.beginColumn + "."
136: + eol;
137: if (expectedTokenSequences.length == 1) {
138: retval += "Was expecting:" + eol + " ";
139: } else {
140: retval += "Was expecting one of:" + eol + " ";
141: }
142: retval += expected;
143: return retval;
144: }
145:
146: /**
147: * The end of line string for this machine.
148: */
149: protected String eol = System.getProperty("line.separator", "\n");
150:
151: /**
152: * Used to convert raw characters to their escaped version
153: * when these raw version cannot be used as part of an ASCII
154: * string literal.
155: */
156: protected String add_escapes(String str) {
157: StringBuffer retval = new StringBuffer();
158: char ch;
159: for (int i = 0; i < str.length(); i++) {
160: switch (str.charAt(i)) {
161: case 0:
162: continue;
163: case '\b':
164: retval.append("\\b");
165: continue;
166: case '\t':
167: retval.append("\\t");
168: continue;
169: case '\n':
170: retval.append("\\n");
171: continue;
172: case '\f':
173: retval.append("\\f");
174: continue;
175: case '\r':
176: retval.append("\\r");
177: continue;
178: case '\"':
179: retval.append("\\\"");
180: continue;
181: case '\'':
182: retval.append("\\\'");
183: continue;
184: case '\\':
185: retval.append("\\\\");
186: continue;
187: default:
188: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
189: String s = "0000" + Integer.toString(ch, 16);
190: retval.append("\\u"
191: + s.substring(s.length() - 4, s.length()));
192: } else {
193: retval.append(ch);
194: }
195: continue;
196: }
197: }
198: return retval.toString();
199: }
200:
201: }
|