| 1 | |
|
| 2 | |
|
| 3 | |
package org.webmacro.parser; |
| 4 | |
|
| 5 | |
|
| 6 | |
public class TokenMgrError extends Error |
| 7 | |
{ |
| 8 | |
private static final long serialVersionUID = 419637845218887887L; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
static final int LEXICAL_ERROR = 0; |
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
static final int STATIC_LEXER_ERROR = 1; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
static final int INVALID_LEXICAL_STATE = 2; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
static final int LOOP_DETECTED = 3; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
int errorCode; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
protected static final String addEscapes(String str) { |
| 45 | 0 | StringBuffer retval = new StringBuffer(); |
| 46 | |
char ch; |
| 47 | 0 | for (int i = 0; i < str.length(); i++) { |
| 48 | 0 | switch (str.charAt(i)) |
| 49 | |
{ |
| 50 | |
case 0 : |
| 51 | 0 | continue; |
| 52 | |
case '\b': |
| 53 | 0 | retval.append("\\b"); |
| 54 | 0 | continue; |
| 55 | |
case '\t': |
| 56 | 0 | retval.append("\\t"); |
| 57 | 0 | continue; |
| 58 | |
case '\n': |
| 59 | 0 | retval.append("\\n"); |
| 60 | 0 | continue; |
| 61 | |
case '\f': |
| 62 | 0 | retval.append("\\f"); |
| 63 | 0 | continue; |
| 64 | |
case '\r': |
| 65 | 0 | retval.append("\\r"); |
| 66 | 0 | continue; |
| 67 | |
case '\"': |
| 68 | 0 | retval.append("\\\""); |
| 69 | 0 | continue; |
| 70 | |
case '\'': |
| 71 | 0 | retval.append("\\\'"); |
| 72 | 0 | continue; |
| 73 | |
case '\\': |
| 74 | 0 | retval.append("\\\\"); |
| 75 | 0 | continue; |
| 76 | |
default: |
| 77 | 0 | if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
| 78 | 0 | String s = "0000" + Integer.toString(ch, 16); |
| 79 | 0 | retval.append("\\u" + s.substring(s.length() - 4, s.length())); |
| 80 | 0 | } else { |
| 81 | 0 | retval.append(ch); |
| 82 | |
} |
| 83 | |
continue; |
| 84 | |
} |
| 85 | |
} |
| 86 | 0 | return retval.toString(); |
| 87 | |
} |
| 88 | |
|
| 89 | |
/** |
| 90 | |
* Returns a detailed message for the Error when it is thrown by the |
| 91 | |
* token manager to indicate a lexical error. |
| 92 | |
* Parameters : |
| 93 | |
* EOFSeen : indicates if EOF caused the lexical error |
| 94 | |
* curLexState : lexical state in which this error occurred |
| 95 | |
* errorLine : line number when the error occurred |
| 96 | |
* errorColumn : column number when the error occurred |
| 97 | |
* errorAfter : prefix that was seen before this error occurred |
| 98 | |
* curchar : the offending character |
| 99 | |
* Note: You can customize the lexical error message by modifying this method. |
| 100 | |
*/ |
| 101 | |
protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { |
| 102 | 0 | return("Lexical error at line " + |
| 103 | |
errorLine + ", column " + |
| 104 | |
errorColumn + ". Encountered: " + |
| 105 | |
(EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + |
| 106 | |
"after : \"" + addEscapes(errorAfter) + "\""); |
| 107 | |
} |
| 108 | |
|
| 109 | |
/** |
| 110 | |
* You can also modify the body of this method to customize your error messages. |
| 111 | |
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not |
| 112 | |
* of end-users concern, so you can return something like : |
| 113 | |
* |
| 114 | |
* "Internal Error : Please file a bug report .... " |
| 115 | |
* |
| 116 | |
* from this method for such cases in the release version of your parser. |
| 117 | |
*/ |
| 118 | |
public String getMessage() { |
| 119 | 0 | return super.getMessage(); |
| 120 | |
} |
| 121 | |
|
| 122 | |
/* |
| 123 | |
* Constructors of various flavors follow. |
| 124 | |
*/ |
| 125 | |
|
| 126 | |
/** No arg constructor. */ |
| 127 | 0 | public TokenMgrError() { |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
/** Constructor with message and reason. */ |
| 131 | |
public TokenMgrError(String message, int reason) { |
| 132 | 0 | super(message); |
| 133 | 0 | errorCode = reason; |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
/** Full Constructor. */ |
| 137 | |
public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { |
| 138 | 0 | this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); |
| 139 | 0 | } |
| 140 | |
} |
| 141 | |
/* JavaCC - OriginalChecksum=704347df73e865ae0e52f827bf72326f (do not edit this line) */ |