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 Error {
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 continue;
50 case '\b':
51 retval.append("\\b");
52 continue;
53 case '\t':
54 retval.append("\\t");
55 continue;
56 case '\n':
57 retval.append("\\n");
58 continue;
59 case '\f':
60 retval.append("\\f");
61 continue;
62 case '\r':
63 retval.append("\\r");
64 continue;
65 case '\"':
66 retval.append("\\\"");
67 continue;
68 case '\'':
69 retval.append("\\\'");
70 continue;
71 case '\\':
72 retval.append("\\\\");
73 continue;
74 default:
75 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
76 final String s = "0000" + Integer.toString(ch, 16);
77 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
78 }
79 else {
80 retval.append(ch);
81 }
82 continue;
83 }
84 }
85 return retval.toString();
86 }
87
88 /**
89 * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error.
90 * Parameters : EOFSeen : indicates if EOF caused the lexicl error curLexState : lexical state in which this error
91 * occured errorLine : line number when the error occured errorColumn : column number when the error occured
92 * errorAfter : prefix that was seen before this error occured curchar : the offending character Note: You can
93 * customize the lexical error message by modifying this method.
94 */
95 protected static String LexicalError(final boolean EOFSeen, final int lexState, final int errorLine,
96 final int errorColumn, final String errorAfter, final char curChar) {
97 return ("Lexical error at line "
98 + errorLine
99 + ", column "
100 + errorColumn
101 + ". Encountered: "
102 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar
103 + "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
104 }
105
106 /**
107 * You can also modify the body of this method to customize your error messages. For example, cases like
108 * LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like :
109 *
110 * "Internal Error : Please file a bug report .... "
111 *
112 * from this method for such cases in the release version of your parser.
113 */
114 @Override
115 public String getMessage() {
116 return super.getMessage();
117 }
118
119 /*
120 * Constructors of various flavors follow.
121 */
122
123 public TokenMgrError() {
124 }
125
126 public TokenMgrError(final String message, final int reason) {
127 super(message);
128 errorCode = reason;
129 }
130
131 public TokenMgrError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn,
132 final String errorAfter, final char curChar, final int reason) {
133 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
134 }
135 }