1/** A parser for TokenStreams.  "parser grammars" result in a subclass
2 *  of this.
3 */
4org.antlr.runtime.Parser = function(input, state) {
5    org.antlr.runtime.Parser.superclass.constructor.call(this, state);
6    this.setTokenStream(input);
7};
8
9org.antlr.lang.extend(org.antlr.runtime.Parser, org.antlr.runtime.BaseRecognizer, {
10    reset: function() {
11        // reset all recognizer state variables
12		org.antlr.runtime.Parser.superclass.reset.call(this);
13		if ( org.antlr.lang.isValue(this.input) ) {
14			this.input.seek(0); // rewind the input
15		}
16	},
17
18    getCurrentInputSymbol: function(input) {
19        return input.LT(1);
20    },
21
22    getMissingSymbol: function(input,
23                               e,
24                               expectedTokenType,
25                               follow)
26    {
27        var tokenText =
28            "<missing "+this.getTokenNames()[expectedTokenType]+">";
29        var t = new org.antlr.runtime.CommonToken(expectedTokenType, tokenText);
30        var current = input.LT(1);
31        var old_current;
32        if ( current.getType() === org.antlr.runtime.Token.EOF ) {
33            old_current = current;
34            current = input.LT(-1);
35            // handle edge case where there are no good tokens in the stream
36            if (!current) {
37                current = old_current;
38            }
39        }
40        t.line = current.getLine();
41        t.charPositionInLine = current.getCharPositionInLine();
42        t.channel = org.antlr.runtime.BaseRecognizer.DEFAULT_TOKEN_CHANNEL;
43        return t;
44    },
45
46
47	/** Set the token stream and reset the parser */
48    setTokenStream: function(input) {
49		this.input = null;
50		this.reset();
51		this.input = input;
52	},
53
54    getTokenStream: function() {
55		return this.input;
56	},
57
58    getSourceName: function() {
59        return this.input.getSourceName();
60    },
61
62    traceIn: function(ruleName, ruleIndex)  {
63		org.antlr.runtime.Parser.superclass.traceIn.call(
64                this, ruleName, ruleIndex, this.input.LT(1));
65	},
66
67    traceOut: function(ruleName, ruleIndex)  {
68		org.antlr.runtime.Parser.superclass.traceOut.call(
69                this, ruleName, ruleIndex, this.input.LT(1));
70	}
71});
72