1 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */
\r
2 /* JavaCCOptions:KEEP_LINE_COL=null */
\r
3 package org.simantics.graphviz.internal.parser;
\r
6 * This exception is thrown when parse errors are encountered.
\r
7 * You can explicitly create objects of this exception type by
\r
8 * calling the method generateParseException in the generated
\r
11 * You can modify this class to customize your error reporting
\r
12 * mechanisms so long as you retain the public fields.
\r
14 public class ParseException extends Exception {
\r
17 * The version identifier for this Serializable class.
\r
18 * Increment only if the <i>serialized</i> form of the
\r
21 private static final long serialVersionUID = 1L;
\r
24 * This constructor is used by the method "generateParseException"
\r
25 * in the generated parser. Calling this constructor generates
\r
26 * a new object of this type with the fields "currentToken",
\r
27 * "expectedTokenSequences", and "tokenImage" set.
\r
29 public ParseException(Token currentTokenVal,
\r
30 int[][] expectedTokenSequencesVal,
\r
31 String[] tokenImageVal
\r
34 super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
\r
35 currentToken = currentTokenVal;
\r
36 expectedTokenSequences = expectedTokenSequencesVal;
\r
37 tokenImage = tokenImageVal;
\r
41 * The following constructors are for use by you for whatever
\r
42 * purpose you can think of. Constructing the exception in this
\r
43 * manner makes the exception behave in the normal way - i.e., as
\r
44 * documented in the class "Throwable". The fields "errorToken",
\r
45 * "expectedTokenSequences", and "tokenImage" do not contain
\r
46 * relevant information. The JavaCC generated code does not use
\r
47 * these constructors.
\r
50 public ParseException() {
\r
54 /** Constructor with message. */
\r
55 public ParseException(String message) {
\r
61 * This is the last token that has been consumed successfully. If
\r
62 * this object has been created due to a parse error, the token
\r
63 * followng this token will (therefore) be the first error token.
\r
65 public Token currentToken;
\r
68 * Each entry in this array is an array of integers. Each array
\r
69 * of integers represents a sequence of tokens (by their ordinal
\r
70 * values) that is expected at this point of the parse.
\r
72 public int[][] expectedTokenSequences;
\r
75 * This is a reference to the "tokenImage" array of the generated
\r
76 * parser within which the parse error occurred. This array is
\r
77 * defined in the generated ...Constants interface.
\r
79 public String[] tokenImage;
\r
82 * It uses "currentToken" and "expectedTokenSequences" to generate a parse
\r
83 * error message and returns it. If this object has been created
\r
84 * due to a parse error, and you do not catch it (it gets thrown
\r
85 * from the parser) the correct error message
\r
88 private static String initialise(Token currentToken,
\r
89 int[][] expectedTokenSequences,
\r
90 String[] tokenImage) {
\r
91 String eol = System.getProperty("line.separator", "\n");
\r
92 StringBuffer expected = new StringBuffer();
\r
94 for (int i = 0; i < expectedTokenSequences.length; i++) {
\r
95 if (maxSize < expectedTokenSequences[i].length) {
\r
96 maxSize = expectedTokenSequences[i].length;
\r
98 for (int j = 0; j < expectedTokenSequences[i].length; j++) {
\r
99 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
\r
101 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
\r
102 expected.append("...");
\r
104 expected.append(eol).append(" ");
\r
106 String retval = "Encountered \"";
\r
107 Token tok = currentToken.next;
\r
108 for (int i = 0; i < maxSize; i++) {
\r
109 if (i != 0) retval += " ";
\r
110 if (tok.kind == 0) {
\r
111 retval += tokenImage[0];
\r
114 retval += " " + tokenImage[tok.kind];
\r
116 retval += add_escapes(tok.image);
\r
120 retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
\r
121 retval += "." + eol;
\r
122 if (expectedTokenSequences.length == 1) {
\r
123 retval += "Was expecting:" + eol + " ";
\r
125 retval += "Was expecting one of:" + eol + " ";
\r
127 retval += expected.toString();
\r
132 * The end of line string for this machine.
\r
134 protected String eol = System.getProperty("line.separator", "\n");
\r
137 * Used to convert raw characters to their escaped version
\r
138 * when these raw version cannot be used as part of an ASCII
\r
141 static String add_escapes(String str) {
\r
142 StringBuffer retval = new StringBuffer();
\r
144 for (int i = 0; i < str.length(); i++) {
\r
145 switch (str.charAt(i))
\r
150 retval.append("\\b");
\r
153 retval.append("\\t");
\r
156 retval.append("\\n");
\r
159 retval.append("\\f");
\r
162 retval.append("\\r");
\r
165 retval.append("\\\"");
\r
168 retval.append("\\\'");
\r
171 retval.append("\\\\");
\r
174 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
\r
175 String s = "0000" + Integer.toString(ch, 16);
\r
176 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
\r
183 return retval.toString();
\r
187 /* JavaCC - OriginalChecksum=32cb99e372d0c543d869005aedf4515b (do not edit this line) */
\r