1
2 package com.quiotix.html.parser;
3
4
5 public class TokenMgrError extends Error
6 {
7
8
9
10
11
12
13
14
15 static final int LEXICAL_ERROR = 0;
16
17
18
19
20 static final int STATIC_LEXER_ERROR = 1;
21
22
23
24
25 static final int INVALID_LEXICAL_STATE = 2;
26
27
28
29
30 static final int LOOP_DETECTED = 3;
31
32
33
34
35
36 int errorCode;
37
38
39
40
41
42 protected static final String addEscapes(String str) {
43 StringBuffer retval = new StringBuffer();
44 char ch;
45 for (int i = 0; i < str.length(); i++) {
46 switch (str.charAt(i))
47 {
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 String s = "0000" + Integer.toString(ch, 16);
77 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
78 } else {
79 retval.append(ch);
80 }
81 continue;
82 }
83 }
84 return retval.toString();
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98
99 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
100 return("Lexical error at line " +
101 errorLine + ", column " +
102 errorColumn + ". Encountered: " +
103 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
104 "after : \"" + addEscapes(errorAfter) + "\"");
105 }
106
107
108
109
110
111
112
113
114
115
116 public String getMessage() {
117 return super.getMessage();
118 }
119
120
121
122
123
124
125 public TokenMgrError() {
126 }
127
128
129 public TokenMgrError(String message, int reason) {
130 super(message);
131 errorCode = reason;
132 }
133
134
135 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
136 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
137 }
138 }