1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.tools.javafx.antlr; |
27 | |
|
28 | |
import com.sun.tools.javafx.tree.JavafxTreeMaker; |
29 | |
import com.sun.tools.javac.tree.JCTree; |
30 | |
import com.sun.tools.javac.tree.JCTree.*; |
31 | |
|
32 | |
import com.sun.tools.javac.code.*; |
33 | |
import com.sun.tools.javac.util.*; |
34 | |
import static com.sun.tools.javac.util.ListBuffer.lb; |
35 | |
import com.sun.tools.javafx.util.MsgSym; |
36 | |
|
37 | |
import org.antlr.runtime.*; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public abstract class AbstractGeneratedParser extends Parser { |
45 | |
|
46 | |
|
47 | |
|
48 | |
protected JavafxTreeMaker F; |
49 | |
|
50 | |
|
51 | |
|
52 | |
protected Log log; |
53 | |
|
54 | |
|
55 | |
protected Source source; |
56 | |
|
57 | |
|
58 | |
protected Name.Table names; |
59 | |
|
60 | 407 | protected java.util.Map<String, String> tokenMap = new java.util.HashMap<String, String>(); |
61 | |
|
62 | |
{ |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 407 | tokenMap.put("ABSTRACT", "abstract"); |
71 | 407 | tokenMap.put("ASSERT", "assert"); |
72 | 407 | tokenMap.put("ATTRIBUTE","attribute"); |
73 | 407 | tokenMap.put("BIND", "bind"); |
74 | 407 | tokenMap.put("BOUND", "bound"); |
75 | 407 | tokenMap.put("BREAK", "break"); |
76 | 407 | tokenMap.put("CLASS", "class"); |
77 | 407 | tokenMap.put("CONTINUE", "continue"); |
78 | 407 | tokenMap.put("DELETE", "delete"); |
79 | 407 | tokenMap.put("FALSE", "false"); |
80 | 407 | tokenMap.put("FOR", "for"); |
81 | 407 | tokenMap.put("FUNCTION", "function"); |
82 | 407 | tokenMap.put("IF", "if"); |
83 | 407 | tokenMap.put("IMPORT", "import"); |
84 | 407 | tokenMap.put("INIT", "init"); |
85 | 407 | tokenMap.put("INSERT", "insert"); |
86 | 407 | tokenMap.put("LET", "let"); |
87 | 407 | tokenMap.put("NEW", "new"); |
88 | 407 | tokenMap.put("NOT", "not"); |
89 | 407 | tokenMap.put("NULL", "null"); |
90 | 407 | tokenMap.put("OVERRIDE", "override"); |
91 | 407 | tokenMap.put("PACKAGE", "package"); |
92 | 407 | tokenMap.put("POSTINIT", "postinit"); |
93 | 407 | tokenMap.put("PRIVATE", "private"); |
94 | 407 | tokenMap.put("PROTECTED", "protected"); |
95 | 407 | tokenMap.put("PUBLIC", "public"); |
96 | 407 | tokenMap.put("READONLY", "readonly"); |
97 | 407 | tokenMap.put("RETURN", "return"); |
98 | 407 | tokenMap.put("SUPER", "super"); |
99 | 407 | tokenMap.put("SIZEOF", "sizeof"); |
100 | 407 | tokenMap.put("STATIC", "static"); |
101 | 407 | tokenMap.put("THIS", "this"); |
102 | 407 | tokenMap.put("THROW", "throw"); |
103 | 407 | tokenMap.put("TRY", "try"); |
104 | 407 | tokenMap.put("TRUE", "true"); |
105 | 407 | tokenMap.put("VAR", "var"); |
106 | 407 | tokenMap.put("WHILE", "while"); |
107 | 407 | tokenMap.put("POUND", "#"); |
108 | 407 | tokenMap.put("LPAREN", "("); |
109 | 407 | tokenMap.put("LBRACKET", "["); |
110 | 407 | tokenMap.put("PLUSPLUS", "++"); |
111 | 407 | tokenMap.put("SUBSUB", "--"); |
112 | 407 | tokenMap.put("PIPE", "|"); |
113 | |
|
114 | |
|
115 | |
|
116 | 407 | tokenMap.put("AFTER", "after"); |
117 | 407 | tokenMap.put("AND", "and"); |
118 | 407 | tokenMap.put("AS", "as"); |
119 | 407 | tokenMap.put("BEFORE", "before"); |
120 | 407 | tokenMap.put("CATCH", "catch"); |
121 | 407 | tokenMap.put("ELSE", "else"); |
122 | 407 | tokenMap.put("EXCLUSIVE", "exclusive"); |
123 | 407 | tokenMap.put("EXTENDS", "extends"); |
124 | 407 | tokenMap.put("FINALLY", "finally"); |
125 | 407 | tokenMap.put("FIRST", "first"); |
126 | 407 | tokenMap.put("FROM", "from"); |
127 | 407 | tokenMap.put("IN", "in"); |
128 | 407 | tokenMap.put("INDEXOF", "indexof"); |
129 | 407 | tokenMap.put("INSTANCEOF", "instanceof"); |
130 | 407 | tokenMap.put("INTO", "into"); |
131 | 407 | tokenMap.put("INVERSE", "inverse"); |
132 | 407 | tokenMap.put("LAST", "last"); |
133 | 407 | tokenMap.put("LAZY", "lazy"); |
134 | 407 | tokenMap.put("ON", "on"); |
135 | 407 | tokenMap.put("OR", "or"); |
136 | 407 | tokenMap.put("REPLACE", "replace"); |
137 | 407 | tokenMap.put("REVERSE", "reverse"); |
138 | 407 | tokenMap.put("STEP", "step"); |
139 | 407 | tokenMap.put("THEN", "then"); |
140 | 407 | tokenMap.put("TYPEOF", "typeof"); |
141 | 407 | tokenMap.put("WITH", "with"); |
142 | 407 | tokenMap.put("WHERE", "where"); |
143 | 407 | tokenMap.put("DOTDOT", ".."); |
144 | 407 | tokenMap.put("RPAREN", ")"); |
145 | 407 | tokenMap.put("RBRACKET", "]"); |
146 | 407 | tokenMap.put("SEMI", ";"); |
147 | 407 | tokenMap.put("COMMA", ","); |
148 | 407 | tokenMap.put("DOT", "."); |
149 | 407 | tokenMap.put("EQEQ", "=="); |
150 | 407 | tokenMap.put("EQ", "="); |
151 | 407 | tokenMap.put("GT", ">"); |
152 | 407 | tokenMap.put("LT", "<"); |
153 | 407 | tokenMap.put("LTGT", "<>"); |
154 | 407 | tokenMap.put("LTEQ", "<="); |
155 | 407 | tokenMap.put("GTEQ", ">="); |
156 | 407 | tokenMap.put("PLUS", "+"); |
157 | 407 | tokenMap.put("SUB", "-"); |
158 | 407 | tokenMap.put("STAR", "*"); |
159 | 407 | tokenMap.put("SLASH", "/"); |
160 | 407 | tokenMap.put("PERCENT", "%"); |
161 | 407 | tokenMap.put("PLUSEQ", "+="); |
162 | 407 | tokenMap.put("SUBEQ", "-="); |
163 | 407 | tokenMap.put("STAREQ", "*="); |
164 | 407 | tokenMap.put("SLASHEQ", "/="); |
165 | 407 | tokenMap.put("PERCENTEQ", "%="); |
166 | 407 | tokenMap.put("COLON", ":"); |
167 | 407 | tokenMap.put("QUES", "?"); |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | 407 | tokenMap.put("DoubleQuoteBody", "double quote string literal"); |
206 | 407 | tokenMap.put("SingleQuoteBody", "single quote string literal"); |
207 | 407 | tokenMap.put("STRING_LITERAL", "string literal"); |
208 | 407 | tokenMap.put("NextIsPercent", "%"); |
209 | 407 | tokenMap.put("QUOTE_LBRACE_STRING_LITERAL", "\" { string literal"); |
210 | 407 | tokenMap.put("LBRACE", "{"); |
211 | 407 | tokenMap.put("RBRACE_QUOTE_STRING_LITERAL", "} \" string literal"); |
212 | 407 | tokenMap.put("RBRACE_LBRACE_STRING_LITERAL", "} { string literal"); |
213 | 407 | tokenMap.put("RBRACE", "}"); |
214 | 407 | tokenMap.put("FORMAT_STRING_LITERAL", "format string literal"); |
215 | 407 | tokenMap.put("TranslationKeyBody", "translation key body"); |
216 | 407 | tokenMap.put("TRANSLATION_KEY", "translation key"); |
217 | 407 | tokenMap.put("DECIMAL_LITERAL", "decimal literal"); |
218 | 407 | tokenMap.put("Digits", "digits"); |
219 | 407 | tokenMap.put("Exponent", "exponent"); |
220 | 407 | tokenMap.put("TIME_LITERAL", "time literal"); |
221 | 407 | tokenMap.put("OCTAL_LITERAL", "octal literal"); |
222 | 407 | tokenMap.put("HexDigit", "hex digit"); |
223 | 407 | tokenMap.put("HEX_LITERAL", "hex literal"); |
224 | 407 | tokenMap.put("RangeDots", ".."); |
225 | 407 | tokenMap.put("FLOATING_POINT_LITERAL", "floating point literal"); |
226 | 407 | tokenMap.put("Letter", "letter"); |
227 | 407 | tokenMap.put("JavaIDDigit", "java ID digit"); |
228 | 407 | tokenMap.put("IDENTIFIER", "identifier"); |
229 | 407 | tokenMap.put("WS", "white space"); |
230 | 407 | tokenMap.put("COMMENT", "comment"); |
231 | 407 | tokenMap.put("LINE_COMMENT", "line comment"); |
232 | 407 | tokenMap.put("LAST_TOKEN", "last token"); |
233 | |
} |
234 | |
|
235 | |
|
236 | 407 | protected String[] fxTokenNames = null; |
237 | |
|
238 | 407 | protected String[][] ruleMap = { |
239 | |
{"module", "the module contents"}, |
240 | |
{"moduleItems", "the module contents"}, |
241 | |
{"moduleItem", "the module contents"}, |
242 | |
{"packageDecl", "a package declaration"}, |
243 | |
{"importDecl", "an import declaration"}, |
244 | |
{"importId", "an import declaration"}, |
245 | |
{"classDefinition", "a class declaration"}, |
246 | |
{"supers", "the 'extends' part of a class declaration"}, |
247 | |
{"classMembers", "the members of a class declaration"}, |
248 | |
{"classMember", "the members of a class declaration"}, |
249 | |
{"functionDefinition", "a function declaration"}, |
250 | |
{"initDefinition", "an 'init' block"}, |
251 | |
{"postInitDefinition", "a 'postinit' block"}, |
252 | |
{"functionModifierFlags", " the modifiers on a function declaration"}, |
253 | |
{"functionModifier", " the modifiers on a function declaration"}, |
254 | |
{"varModifierFlags", " the modifiers on an attribute/var declaration"}, |
255 | |
{"varModifier", " the modifiers on an attribute/var declaration"}, |
256 | |
{"classModifierFlags", " the modifiers on a class declaration"}, |
257 | |
{"classModifier", " the modifiers on a class declaration"}, |
258 | |
{"accessModifier", "an access modifier"}, |
259 | |
{"formalParameters", " the parameters of a function declaration"}, |
260 | |
{"formalParameter", " a formal parameter"}, |
261 | |
{"blockExpression", "a block expression"}, |
262 | |
{"blockComponent", "a component of a block"}, |
263 | |
{"variableDeclaration", "an attribute/variable declaration"}, |
264 | |
{"variableLabel", "an attribute/variable declaration"}, |
265 | |
{"boundExpression", "an expression"}, |
266 | |
{"inClause", "the 'in' clause of a 'for' expression"}, |
267 | |
{"elseClause", "the 'else' clause of an 'if' expression"}, |
268 | |
{"assignmentOpExpression", "an operator assignment expression"}, |
269 | |
{"primaryExpression", "an expression"}, |
270 | |
{"stringExpressionInner", "a string expression"}, |
271 | |
{"bracketExpression", "a sequence creation expression"}, |
272 | |
{"expressionList", "a list of expressions"}, |
273 | |
{"expressionListOpt", "a list of expressions"}, |
274 | |
{"type", "a type specification"}, |
275 | |
{"typeArgList", "a type specification"}, |
276 | |
{"typeArg", "a type specification"}, |
277 | |
{"typeReference", "a type specification"}, |
278 | |
{"cardinality", "a type specification"}, |
279 | |
{"typeName", "a type specification"}, |
280 | |
{"genericArgument", "a type specification"}, |
281 | |
{"qualident", "an identifier"}, |
282 | |
{"name", "an identifier"}, |
283 | |
{"paramNameOpt", "an optional identifier"} |
284 | |
}; |
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
protected JCErroneous errorTree; |
290 | |
|
291 | |
|
292 | |
protected void initialize(Context context) { |
293 | 407 | this.F = (JavafxTreeMaker)JavafxTreeMaker.instance(context); |
294 | 407 | this.log = Log.instance(context); |
295 | 407 | this.names = Name.Table.instance(context); |
296 | 407 | this.source = Source.instance(context); |
297 | 407 | } |
298 | |
|
299 | |
protected AbstractGeneratedParser(TokenStream input) { |
300 | 0 | super(input); |
301 | 0 | } |
302 | |
|
303 | |
protected AbstractGeneratedParser(TokenStream input, RecognizerSharedState state) { |
304 | 407 | super(input, state); |
305 | 407 | } |
306 | |
|
307 | |
protected void mismatch(IntStream input, int ttype, BitSet follow) |
308 | |
throws RecognitionException { |
309 | |
|
310 | 6 | super.mismatch(input, ttype, follow); |
311 | 0 | } |
312 | |
|
313 | |
protected String stackPositionDescription(String ruleName) { |
314 | |
|
315 | 218 | for (String[] pair : ruleMap) { |
316 | 216 | if (pair[0].equals(ruleName)) { |
317 | 7 | return pair[1]; |
318 | |
} |
319 | |
} |
320 | 2 | StringBuffer sb = new StringBuffer(ruleName.length()+1); |
321 | 2 | switch (ruleName.charAt(0)) { |
322 | |
case 'a': case 'e': case 'i': case 'o': case 'u': |
323 | 1 | sb.append("an "); |
324 | 1 | break; |
325 | |
default: |
326 | 1 | sb.append("a "); |
327 | |
break; |
328 | |
} |
329 | 33 | for (char ch : ruleName.toCharArray()) { |
330 | 31 | if (Character.isUpperCase(ch)) { |
331 | 2 | sb.append(' '); |
332 | 2 | sb.append(Character.toLowerCase(ch)); |
333 | |
} else { |
334 | 29 | sb.append(ch); |
335 | |
} |
336 | |
} |
337 | 2 | return sb.toString(); |
338 | |
} |
339 | |
|
340 | 108 | protected enum TokenClassification { |
341 | 12 | KEYWORD { |
342 | |
String forHumans() { |
343 | 3 | return "a keyword"; |
344 | |
} |
345 | |
}, |
346 | 12 | OPERATOR { |
347 | |
String forHumans() { |
348 | 4 | return "an operator"; |
349 | |
} |
350 | |
}, |
351 | 12 | IDENTIFIER { |
352 | |
String forHumans() { |
353 | 1 | return "an identifier"; |
354 | |
} |
355 | |
}, |
356 | 12 | UNKNOWN { |
357 | |
String forHumans() { |
358 | 0 | return "an unknown type of token"; |
359 | |
} |
360 | |
}; |
361 | |
abstract String forHumans(); |
362 | |
}; |
363 | |
|
364 | 407 | protected TokenClassification[] tokenClassMap = new TokenClassification[v3Parser.LAST_TOKEN + 1]; |
365 | |
{ |
366 | |
|
367 | |
|
368 | 68783 | for (int index = 0; index <= v3Parser.LAST_TOKEN; index += 1) { |
369 | 68376 | tokenClassMap[index] = TokenClassification.UNKNOWN; |
370 | |
} |
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | 407 | tokenClassMap[v3Parser.ABSTRACT] = TokenClassification.KEYWORD; |
377 | 407 | tokenClassMap[v3Parser.ASSERT] = TokenClassification.KEYWORD; |
378 | 407 | tokenClassMap[v3Parser.ATTRIBUTE] = TokenClassification.KEYWORD; |
379 | 407 | tokenClassMap[v3Parser.BIND] = TokenClassification.KEYWORD; |
380 | 407 | tokenClassMap[v3Parser.BOUND] = TokenClassification.KEYWORD; |
381 | 407 | tokenClassMap[v3Parser.BREAK] = TokenClassification.KEYWORD; |
382 | 407 | tokenClassMap[v3Parser.CLASS] = TokenClassification.KEYWORD; |
383 | 407 | tokenClassMap[v3Parser.CONTINUE] = TokenClassification.KEYWORD; |
384 | 407 | tokenClassMap[v3Parser.DELETE] = TokenClassification.KEYWORD; |
385 | 407 | tokenClassMap[v3Parser.FALSE] = TokenClassification.KEYWORD; |
386 | 407 | tokenClassMap[v3Parser.FOR] = TokenClassification.KEYWORD; |
387 | 407 | tokenClassMap[v3Parser.FUNCTION] = TokenClassification.KEYWORD; |
388 | 407 | tokenClassMap[v3Parser.IF] = TokenClassification.KEYWORD; |
389 | 407 | tokenClassMap[v3Parser.IMPORT] = TokenClassification.KEYWORD; |
390 | 407 | tokenClassMap[v3Parser.INIT] = TokenClassification.KEYWORD; |
391 | 407 | tokenClassMap[v3Parser.INSERT] = TokenClassification.KEYWORD; |
392 | 407 | tokenClassMap[v3Parser.LET] = TokenClassification.KEYWORD; |
393 | 407 | tokenClassMap[v3Parser.NEW] = TokenClassification.KEYWORD; |
394 | 407 | tokenClassMap[v3Parser.NOT] = TokenClassification.KEYWORD; |
395 | 407 | tokenClassMap[v3Parser.NULL] = TokenClassification.KEYWORD; |
396 | 407 | tokenClassMap[v3Parser.OVERRIDE] = TokenClassification.KEYWORD; |
397 | 407 | tokenClassMap[v3Parser.PACKAGE] = TokenClassification.KEYWORD; |
398 | 407 | tokenClassMap[v3Parser.POSTINIT] = TokenClassification.KEYWORD; |
399 | 407 | tokenClassMap[v3Parser.PRIVATE] = TokenClassification.KEYWORD; |
400 | 407 | tokenClassMap[v3Parser.PROTECTED] = TokenClassification.KEYWORD; |
401 | 407 | tokenClassMap[v3Parser.PUBLIC] = TokenClassification.KEYWORD; |
402 | 407 | tokenClassMap[v3Parser.READONLY] = TokenClassification.KEYWORD; |
403 | 407 | tokenClassMap[v3Parser.RETURN] = TokenClassification.KEYWORD; |
404 | 407 | tokenClassMap[v3Parser.SUPER] = TokenClassification.KEYWORD; |
405 | 407 | tokenClassMap[v3Parser.SIZEOF] = TokenClassification.KEYWORD; |
406 | 407 | tokenClassMap[v3Parser.STATIC] = TokenClassification.KEYWORD; |
407 | 407 | tokenClassMap[v3Parser.THIS] = TokenClassification.KEYWORD; |
408 | 407 | tokenClassMap[v3Parser.THROW] = TokenClassification.KEYWORD; |
409 | 407 | tokenClassMap[v3Parser.TRY] = TokenClassification.KEYWORD; |
410 | 407 | tokenClassMap[v3Parser.TRUE] = TokenClassification.KEYWORD; |
411 | 407 | tokenClassMap[v3Parser.VAR] = TokenClassification.KEYWORD; |
412 | 407 | tokenClassMap[v3Parser.WHILE] = TokenClassification.KEYWORD; |
413 | 407 | tokenClassMap[v3Parser.AFTER] = TokenClassification.KEYWORD; |
414 | 407 | tokenClassMap[v3Parser.AND] = TokenClassification.KEYWORD; |
415 | 407 | tokenClassMap[v3Parser.AS] = TokenClassification.KEYWORD; |
416 | 407 | tokenClassMap[v3Parser.BEFORE] = TokenClassification.KEYWORD; |
417 | 407 | tokenClassMap[v3Parser.CATCH] = TokenClassification.KEYWORD; |
418 | 407 | tokenClassMap[v3Parser.ELSE] = TokenClassification.KEYWORD; |
419 | 407 | tokenClassMap[v3Parser.EXCLUSIVE] = TokenClassification.KEYWORD; |
420 | 407 | tokenClassMap[v3Parser.EXTENDS] = TokenClassification.KEYWORD; |
421 | 407 | tokenClassMap[v3Parser.FINALLY] = TokenClassification.KEYWORD; |
422 | 407 | tokenClassMap[v3Parser.FIRST] = TokenClassification.KEYWORD; |
423 | 407 | tokenClassMap[v3Parser.FROM] = TokenClassification.KEYWORD; |
424 | 407 | tokenClassMap[v3Parser.IN] = TokenClassification.KEYWORD; |
425 | 407 | tokenClassMap[v3Parser.INDEXOF] = TokenClassification.KEYWORD; |
426 | 407 | tokenClassMap[v3Parser.INSTANCEOF] = TokenClassification.KEYWORD; |
427 | 407 | tokenClassMap[v3Parser.INTO] = TokenClassification.KEYWORD; |
428 | 407 | tokenClassMap[v3Parser.INVERSE] = TokenClassification.KEYWORD; |
429 | 407 | tokenClassMap[v3Parser.LAST] = TokenClassification.KEYWORD; |
430 | 407 | tokenClassMap[v3Parser.LAZY] = TokenClassification.KEYWORD; |
431 | 407 | tokenClassMap[v3Parser.ON] = TokenClassification.KEYWORD; |
432 | 407 | tokenClassMap[v3Parser.OR] = TokenClassification.KEYWORD; |
433 | 407 | tokenClassMap[v3Parser.REPLACE] = TokenClassification.KEYWORD; |
434 | 407 | tokenClassMap[v3Parser.REVERSE] = TokenClassification.KEYWORD; |
435 | 407 | tokenClassMap[v3Parser.STEP] = TokenClassification.KEYWORD; |
436 | 407 | tokenClassMap[v3Parser.THEN] = TokenClassification.KEYWORD; |
437 | 407 | tokenClassMap[v3Parser.TYPEOF] = TokenClassification.KEYWORD; |
438 | 407 | tokenClassMap[v3Parser.WITH] = TokenClassification.KEYWORD; |
439 | 407 | tokenClassMap[v3Parser.WHERE] = TokenClassification.KEYWORD; |
440 | 407 | tokenClassMap[v3Parser.TWEEN] = TokenClassification.KEYWORD; |
441 | |
|
442 | 407 | tokenClassMap[v3Parser.POUND] = TokenClassification.OPERATOR; |
443 | 407 | tokenClassMap[v3Parser.LPAREN] = TokenClassification.OPERATOR; |
444 | 407 | tokenClassMap[v3Parser.LBRACKET] = TokenClassification.OPERATOR; |
445 | 407 | tokenClassMap[v3Parser.PLUSPLUS] = TokenClassification.OPERATOR; |
446 | 407 | tokenClassMap[v3Parser.SUBSUB] = TokenClassification.OPERATOR; |
447 | 407 | tokenClassMap[v3Parser.PIPE] = TokenClassification.OPERATOR; |
448 | 407 | tokenClassMap[v3Parser.DOTDOT] = TokenClassification.OPERATOR; |
449 | 407 | tokenClassMap[v3Parser.RPAREN] = TokenClassification.OPERATOR; |
450 | 407 | tokenClassMap[v3Parser.RBRACKET] = TokenClassification.OPERATOR; |
451 | 407 | tokenClassMap[v3Parser.SEMI] = TokenClassification.OPERATOR; |
452 | 407 | tokenClassMap[v3Parser.COMMA] = TokenClassification.OPERATOR; |
453 | 407 | tokenClassMap[v3Parser.DOT] = TokenClassification.OPERATOR; |
454 | 407 | tokenClassMap[v3Parser.EQEQ] = TokenClassification.OPERATOR; |
455 | 407 | tokenClassMap[v3Parser.EQ] = TokenClassification.OPERATOR; |
456 | 407 | tokenClassMap[v3Parser.GT] = TokenClassification.OPERATOR; |
457 | 407 | tokenClassMap[v3Parser.LT] = TokenClassification.OPERATOR; |
458 | 407 | tokenClassMap[v3Parser.LTGT] = TokenClassification.OPERATOR; |
459 | 407 | tokenClassMap[v3Parser.LTEQ] = TokenClassification.OPERATOR; |
460 | 407 | tokenClassMap[v3Parser.GTEQ] = TokenClassification.OPERATOR; |
461 | 407 | tokenClassMap[v3Parser.PLUS] = TokenClassification.OPERATOR; |
462 | 407 | tokenClassMap[v3Parser.SUB] = TokenClassification.OPERATOR; |
463 | 407 | tokenClassMap[v3Parser.STAR] = TokenClassification.OPERATOR; |
464 | 407 | tokenClassMap[v3Parser.SLASH] = TokenClassification.OPERATOR; |
465 | 407 | tokenClassMap[v3Parser.PERCENT] = TokenClassification.OPERATOR; |
466 | 407 | tokenClassMap[v3Parser.PLUSEQ] = TokenClassification.OPERATOR; |
467 | 407 | tokenClassMap[v3Parser.SUBEQ] = TokenClassification.OPERATOR; |
468 | 407 | tokenClassMap[v3Parser.STAREQ] = TokenClassification.OPERATOR; |
469 | 407 | tokenClassMap[v3Parser.SLASHEQ] = TokenClassification.OPERATOR; |
470 | 407 | tokenClassMap[v3Parser.PERCENTEQ] = TokenClassification.OPERATOR; |
471 | 407 | tokenClassMap[v3Parser.COLON] = TokenClassification.OPERATOR; |
472 | 407 | tokenClassMap[v3Parser.QUES] = TokenClassification.OPERATOR; |
473 | 407 | tokenClassMap[v3Parser.SUCHTHAT] = TokenClassification.OPERATOR; |
474 | |
|
475 | 407 | tokenClassMap[v3Parser.IDENTIFIER] = TokenClassification.IDENTIFIER; |
476 | |
} |
477 | |
|
478 | |
private TokenClassification classifyToken(Token t) { |
479 | 9 | TokenClassification result = TokenClassification.UNKNOWN; |
480 | 9 | int tokenType = t.getType(); |
481 | 9 | if ((tokenType >= 0) && tokenType < tokenClassMap.length) { |
482 | 9 | result = tokenClassMap[tokenType]; |
483 | |
} |
484 | 9 | return result; |
485 | |
} |
486 | |
|
487 | |
public String getErrorMessage(RecognitionException e, String[] tokenNames) { |
488 | 9 | java.util.List stack = getRuleInvocationStack(e, this.getClass().getName()); |
489 | 9 | String stackTop = stack.get(stack.size()-1).toString(); |
490 | 9 | String posDescription = stackPositionDescription(stackTop); |
491 | 9 | StringBuffer mb = new StringBuffer(); |
492 | 9 | if (e instanceof MismatchedTokenException) { |
493 | 4 | MismatchedTokenException mte = (MismatchedTokenException) e; |
494 | |
|
495 | 4 | mb.append("Sorry, I was trying to understand "); |
496 | 4 | mb.append(posDescription); |
497 | 4 | mb.append(" but I got confused when I saw "); |
498 | 4 | mb.append(getTokenErrorDisplay(e.token)); |
499 | 4 | TokenClassification tokenClass = classifyToken(e.token); |
500 | 4 | if (tokenClass != TokenClassification.UNKNOWN) { |
501 | 4 | mb.append(" which is "); |
502 | 4 | mb.append(tokenClass.forHumans()); |
503 | |
} |
504 | 4 | if (mte.expecting != Token.EOF) { |
505 | 4 | mb.append(".\n Perhaps you are missing a "); |
506 | 4 | mb.append("'" + tokenNames[mte.expecting]+"'"); |
507 | |
} |
508 | 4 | } else if (e instanceof NoViableAltException) { |
509 | 5 | NoViableAltException nvae = (NoViableAltException) e; |
510 | |
|
511 | 5 | mb.append("Sorry, I was trying to understand "); |
512 | 5 | mb.append(posDescription); |
513 | 5 | mb.append(" but I got confused when I saw "); |
514 | 5 | mb.append(getTokenErrorDisplay(e.token)); |
515 | 5 | TokenClassification tokenClass = classifyToken(e.token); |
516 | 5 | if (tokenClass != TokenClassification.UNKNOWN) { |
517 | 4 | mb.append(" which is "); |
518 | 4 | mb.append(tokenClass.forHumans()); |
519 | |
} |
520 | 5 | } else { |
521 | 0 | mb.append( super.getErrorMessage(e, tokenNames) ); |
522 | |
} |
523 | 9 | return mb.toString(); |
524 | |
} |
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
@Override |
534 | |
public void displayRecognitionError(String[] tokenNames, RecognitionException e) { |
535 | 9 | int pos = ((CommonToken)(e.token)).getStartIndex(); |
536 | |
|
537 | |
|
538 | |
|
539 | 9 | String msg = getErrorMessage(e, getFXTokenNames(tokenNames)); |
540 | 9 | log.error(pos, MsgSym.MESSAGE_JAVAFX_GENERALERROR, msg); |
541 | 9 | } |
542 | |
|
543 | |
protected String[] getFXTokenNames(String[] tokenNames) { |
544 | |
|
545 | 9 | if (fxTokenNames != null) { |
546 | 3 | return fxTokenNames; |
547 | |
} else { |
548 | |
|
549 | 6 | fxTokenNames = new String[tokenNames.length]; |
550 | 6 | int count = 0; |
551 | 1014 | for (String tokenName:tokenNames) { |
552 | 1008 | String fxTokenName = tokenMap.get(tokenName); |
553 | 1008 | if (fxTokenName == null) { |
554 | 270 | fxTokenNames[count] = tokenName; |
555 | |
} else { |
556 | 738 | fxTokenNames[count] = fxTokenName; |
557 | |
} |
558 | 1008 | count++; |
559 | |
} |
560 | |
|
561 | 6 | return fxTokenNames; |
562 | |
} |
563 | |
|
564 | |
} |
565 | |
|
566 | |
protected int pos(Token tok) { |
567 | |
|
568 | 3 | return ((CommonToken)tok).getStartIndex(); |
569 | |
} |
570 | |
|
571 | |
protected List noJCTrees() { |
572 | 0 | return List.<JCTree>nil(); |
573 | |
} |
574 | |
|
575 | |
protected List<JCAnnotation> noJCAnnotations() { |
576 | 0 | return List.<JCAnnotation>nil(); |
577 | |
} |
578 | |
} |