|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package net.sourceforge.pmd.jsp.ast; |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| public class ParseException extends net.sourceforge.pmd.ast.ParseException { |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
0
| public ParseException(Token currentTokenVal,
|
|
33 |
| int[][] expectedTokenSequencesVal, |
|
34 |
| String[] tokenImageVal) { |
|
35 |
0
| super("");
|
|
36 |
0
| specialConstructor = true;
|
|
37 |
0
| currentToken = currentTokenVal;
|
|
38 |
0
| expectedTokenSequences = expectedTokenSequencesVal;
|
|
39 |
0
| tokenImage = tokenImageVal;
|
|
40 |
| } |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
0
| public ParseException() {
|
|
53 |
0
| super();
|
|
54 |
0
| specialConstructor = false;
|
|
55 |
| } |
|
56 |
| |
|
57 |
0
| public ParseException(String message) {
|
|
58 |
0
| super(message);
|
|
59 |
0
| specialConstructor = false;
|
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| protected boolean specialConstructor; |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| public Token currentToken; |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| public int[][] expectedTokenSequences; |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| public String[] tokenImage; |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
0
| public String getMessage() {
|
|
101 |
0
| if (!specialConstructor) {
|
|
102 |
0
| return super.getMessage();
|
|
103 |
| } |
|
104 |
0
| String expected = "";
|
|
105 |
0
| int maxSize = 0;
|
|
106 |
0
| for (int i = 0; i < expectedTokenSequences.length; i++) {
|
|
107 |
0
| if (maxSize < expectedTokenSequences[i].length) {
|
|
108 |
0
| maxSize = expectedTokenSequences[i].length;
|
|
109 |
| } |
|
110 |
0
| for (int j = 0; j < expectedTokenSequences[i].length; j++) {
|
|
111 |
0
| expected += tokenImage[expectedTokenSequences[i][j]] + " ";
|
|
112 |
| } |
|
113 |
0
| if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
|
|
114 |
0
| expected += "...";
|
|
115 |
| } |
|
116 |
0
| expected += eol + " ";
|
|
117 |
| } |
|
118 |
0
| String retval = "Encountered \"";
|
|
119 |
0
| Token tok = currentToken.next;
|
|
120 |
0
| for (int i = 0; i < maxSize; i++) {
|
|
121 |
0
| if (i != 0) retval += " ";
|
|
122 |
0
| if (tok.kind == 0) {
|
|
123 |
0
| retval += tokenImage[0];
|
|
124 |
0
| break;
|
|
125 |
| } |
|
126 |
0
| retval += add_escapes(tok.image);
|
|
127 |
0
| tok = tok.next;
|
|
128 |
| } |
|
129 |
0
| retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
|
|
130 |
0
| retval += "." + eol;
|
|
131 |
0
| if (expectedTokenSequences.length == 1) {
|
|
132 |
0
| retval += "Was expecting:" + eol + " ";
|
|
133 |
| } else { |
|
134 |
0
| retval += "Was expecting one of:" + eol + " ";
|
|
135 |
| } |
|
136 |
0
| retval += expected;
|
|
137 |
0
| return retval;
|
|
138 |
| } |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| protected String eol = System.getProperty("line.separator", "\n"); |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
0
| protected String add_escapes(String str) {
|
|
151 |
0
| StringBuffer retval = new StringBuffer();
|
|
152 |
0
| char ch;
|
|
153 |
0
| for (int i = 0; i < str.length(); i++) {
|
|
154 |
0
| switch (str.charAt(i)) {
|
|
155 |
0
| case 0:
|
|
156 |
0
| continue;
|
|
157 |
0
| case '\b':
|
|
158 |
0
| retval.append("\\b");
|
|
159 |
0
| continue;
|
|
160 |
0
| case '\t':
|
|
161 |
0
| retval.append("\\t");
|
|
162 |
0
| continue;
|
|
163 |
0
| case '\n':
|
|
164 |
0
| retval.append("\\n");
|
|
165 |
0
| continue;
|
|
166 |
0
| case '\f':
|
|
167 |
0
| retval.append("\\f");
|
|
168 |
0
| continue;
|
|
169 |
0
| case '\r':
|
|
170 |
0
| retval.append("\\r");
|
|
171 |
0
| continue;
|
|
172 |
0
| case '\"':
|
|
173 |
0
| retval.append("\\\"");
|
|
174 |
0
| continue;
|
|
175 |
0
| case '\'':
|
|
176 |
0
| retval.append("\\\'");
|
|
177 |
0
| continue;
|
|
178 |
0
| case '\\':
|
|
179 |
0
| retval.append("\\\\");
|
|
180 |
0
| continue;
|
|
181 |
0
| default:
|
|
182 |
0
| if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
|
|
183 |
0
| String s = "0000" + Integer.toString(ch, 16);
|
|
184 |
0
| retval.append("\\u" + s.substring(s.length() - 4, s.length()));
|
|
185 |
| } else { |
|
186 |
0
| retval.append(ch);
|
|
187 |
| } |
|
188 |
0
| continue;
|
|
189 |
| } |
|
190 |
| } |
|
191 |
0
| return retval.toString();
|
|
192 |
| } |
|
193 |
| |
|
194 |
| } |