01: package antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: import antlr.collections.AST;
09:
10: public class NoViableAltException extends RecognitionException {
11: public Token token;
12: public AST node; // handles parsing and treeparsing
13:
14: public NoViableAltException(AST t) {
15: super ("NoViableAlt", "<AST>", t.getLine(), t.getColumn());
16: node = t;
17: }
18:
19: public NoViableAltException(Token t, String fileName_) {
20: super ("NoViableAlt", fileName_, t.getLine(), t.getColumn());
21: token = t;
22: }
23:
24: /**
25: * Returns a clean error message (no line number/column information)
26: */
27: public String getMessage() {
28: if (token != null) {
29: return "unexpected token: " + token.getText();
30: }
31:
32: // must a tree parser error if token==null
33: if (node == TreeParser.ASTNULL) {
34: return "unexpected end of subtree";
35: }
36: return "unexpected AST node: " + node.toString();
37: }
38: }
|