1 package net.sourceforge.pmd.lang.vm.ast;
2
3 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
4
5 public class TokenMgrError extends RuntimeException {
6 /*
7 * Ordinals for various reasons why an Error of this type can be thrown.
8 */
9
10 /**
11 *
12 */
13 private static final long serialVersionUID = 1L;
14
15 /**
16 * Lexical error occured.
17 */
18 static final int LEXICAL_ERROR = 0;
19
20 /**
21 * An attempt wass made to create a second instance of a static token manager.
22 */
23 static final int STATIC_LEXER_ERROR = 1;
24
25 /**
26 * Tried to change to an invalid lexical state.
27 */
28 static final int INVALID_LEXICAL_STATE = 2;
29
30 /**
31 * Detected (and bailed out of) an infinite loop in the token manager.
32 */
33 static final int LOOP_DETECTED = 3;
34
35 /**
36 * Indicates the reason why the exception is thrown. It will have one of the above 4 values.
37 */
38 int errorCode;
39
40 /**
41 * Replaces unprintable characters by their espaced (or unicode escaped) equivalents in the given string
42 */
43 protected static final String addEscapes(final String str) {
44 final StringBuffer retval = new StringBuffer();
45 char ch;
46 for (int i = 0; i < str.length(); i++) {
47 switch (str.charAt(i)) {
48 case 0:
49 break;
50 case '\b':
51 retval.append("\\b");
52 break;
53 case '\t':
54 retval.append("\\t");
55 break;
56 case '\n':
57 retval.append("\\n");
58 break;
59 case '\f':
60 retval.append("\\f");
61 break;
62 case '\r':
63 retval.append("\\r");
64 break;
65 case '\"':
66 retval.append("\\\"");
67 break;
68 case '\'':
69 retval.append("\\\'");
70 break;
71 case '\\':
72 retval.append("\\\\");
73 break;
74 default:
75 ch = str.charAt(i);
76 if (ch < 0x20 || ch > 0x7e) {
77 final String s = "0000" + Integer.toString(ch, 16);
78 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
79 }
80 else {
81 retval.append(ch);
82 }
83 break;
84 }
85 }
86 return retval.toString();
87 }
88
89 /**
90 * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error.
91 * Parameters : EOFSeen : indicates if EOF caused the lexicl error curLexState : lexical state in which this error
92 * occured errorLine : line number when the error occured errorColumn : column number when the error occured
93 * errorAfter : prefix that was seen before this error occured curchar : the offending character Note: You can
94 * customize the lexical error message by modifying this method.
95 */
96 protected static String LexicalError(final boolean EOFSeen, final int lexState, final int errorLine,
97 final int errorColumn, final String errorAfter, final char curChar) {
98 return ("Lexical error at line "
99 + errorLine
100 + ", column "
101 + errorColumn
102 + ". Encountered: "
103 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar
104 + "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
105 }
106
107 /*
108 * Constructors of various flavors follow.
109 */
110
111 public TokenMgrError() {
112 }
113
114 public TokenMgrError(final String message, final int reason) {
115 super(message);
116 errorCode = reason;
117 }
118
119 public TokenMgrError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn,
120 final String errorAfter, final char curChar, final int reason) {
121 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
122 }
123 }