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