1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
\r
3 package org.simantics.spreadsheet.graph.parser;
\r
5 /** Token Manager Error. */
\r
6 public class TokenMgrError extends Error
\r
10 * The version identifier for this Serializable class.
\r
11 * Increment only if the <i>serialized</i> form of the
\r
14 private static final long serialVersionUID = 1L;
\r
17 * Ordinals for various reasons why an Error of this type can be thrown.
\r
21 * Lexical error occurred.
\r
23 static final int LEXICAL_ERROR = 0;
\r
26 * An attempt was made to create a second instance of a static token manager.
\r
28 static final int STATIC_LEXER_ERROR = 1;
\r
31 * Tried to change to an invalid lexical state.
\r
33 static final int INVALID_LEXICAL_STATE = 2;
\r
36 * Detected (and bailed out of) an infinite loop in the token manager.
\r
38 static final int LOOP_DETECTED = 3;
\r
41 * Indicates the reason why the exception is thrown. It will have
\r
42 * one of the above 4 values.
\r
47 * Replaces unprintable characters by their escaped (or unicode escaped)
\r
48 * equivalents in the given string
\r
50 protected static final String addEscapes(String str) {
\r
51 StringBuffer retval = new StringBuffer();
\r
53 for (int i = 0; i < str.length(); i++) {
\r
54 switch (str.charAt(i))
\r
59 retval.append("\\b");
\r
62 retval.append("\\t");
\r
65 retval.append("\\n");
\r
68 retval.append("\\f");
\r
71 retval.append("\\r");
\r
74 retval.append("\\\"");
\r
77 retval.append("\\\'");
\r
80 retval.append("\\\\");
\r
83 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
\r
84 String s = "0000" + Integer.toString(ch, 16);
\r
85 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
\r
92 return retval.toString();
\r
96 * Returns a detailed message for the Error when it is thrown by the
\r
97 * token manager to indicate a lexical error.
\r
99 * EOFSeen : indicates if EOF caused the lexical error
\r
100 * curLexState : lexical state in which this error occurred
\r
101 * errorLine : line number when the error occurred
\r
102 * errorColumn : column number when the error occurred
\r
103 * errorAfter : prefix that was seen before this error occurred
\r
104 * curchar : the offending character
\r
105 * Note: You can customize the lexical error message by modifying this method.
\r
107 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
\r
108 return("Lexical error at line " +
\r
109 errorLine + ", column " +
\r
110 errorColumn + ". Encountered: " +
\r
111 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
\r
112 "after : \"" + addEscapes(errorAfter) + "\"");
\r
116 * You can also modify the body of this method to customize your error messages.
\r
117 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
\r
118 * of end-users concern, so you can return something like :
\r
120 * "Internal Error : Please file a bug report .... "
\r
122 * from this method for such cases in the release version of your parser.
\r
124 public String getMessage() {
\r
125 return super.getMessage();
\r
129 * Constructors of various flavors follow.
\r
132 /** No arg constructor. */
\r
133 public TokenMgrError() {
\r
136 /** Constructor with message and reason. */
\r
137 public TokenMgrError(String message, int reason) {
\r
139 errorCode = reason;
\r
142 /** Full Constructor. */
\r
143 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
\r
144 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
\r
147 /* JavaCC - OriginalChecksum=4539633441e7ba2ec0e4bccd1a2f8c27 (do not edit this line) */
\r