• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1org.antlr.runtime.tree.CommonErrorNode = function(input, start, stop, e) {
2    if ( !stop ||
3            (stop.getTokenIndex() < start.getTokenIndex() &&
4             stop.getType()!=org.antlr.runtime.Token.EOF) )
5    {
6        // sometimes resync does not consume a token (when LT(1) is
7        // in follow set.  So, stop will be 1 to left to start. adjust.
8        // Also handle case where start is the first token and no token
9        // is consumed during recovery; LT(-1) will return null.
10        stop = start;
11    }
12    this.input = input;
13    this.start = start;
14    this.stop = stop;
15    this.trappedException = e;
16};
17
18org.antlr.lang.extend(org.antlr.runtime.tree.CommonErrorNode, org.antlr.runtime.tree.CommonTree, {
19    isNil: function() {
20        return false;
21    },
22
23    getType: function() {
24        return org.antlr.runtime.Token.INVALID_TOKEN_TYPE;
25    },
26
27    getText: function() {
28        var badText = null;
29        if ( this.start instanceof org.antlr.runtime.Token ) {
30            var i = this.start.getTokenIndex();
31            var j = this.stop.getTokenIndex();
32            if ( this.stop.getType() === org.antlr.runtime.Token.EOF ) {
33                j = this.input.size();
34            }
35            badText = this.input.toString(i, j);
36        }
37        else if ( this.start instanceof org.antlr.runtime.tree.Tree ) {
38            badText = this.input.toString(this.start, this.stop);
39        }
40        else {
41            // people should subclass if they alter the tree type so this
42            // next one is for sure correct.
43            badText = "<unknown>";
44        }
45        return badText;
46    },
47
48    toString: function() {
49        if ( this.trappedException instanceof org.antlr.runtime.MissingTokenException ) {
50            return "<missing type: "+
51                   this.trappedException.getMissingType()+
52                   ">";
53        }
54        else if ( this.trappedException instanceof org.antlr.runtime.UnwantedTokenException ) {
55            return "<extraneous: "+
56                   this.trappedException.getUnexpectedToken()+
57                   ", resync="+this.getText()+">";
58        }
59        else if ( this.trappedException instanceof org.antlr.runtime.MismatchedTokenException ) {
60            return "<mismatched token: "+this.trappedException.token+", resync="+this.getText()+">";
61        }
62        else if ( this.trappedException instanceof org.antlr.runtime.NoViableAltException ) {
63            return "<unexpected: "+this.trappedException.token+
64                   ", resync="+this.getText()+">";
65        }
66        return "<error: "+this.getText()+">";
67    }
68});
69