• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/** The set of fields needed by an abstract recognizer to recognize input
2 *  and recover from errors etc...  As a separate state object, it can be
3 *  shared among multiple grammars; e.g., when one grammar imports another.
4 *
5 *  These fields are publically visible but the actual state pointer per
6 *  parser is protected.
7 */
8org.antlr.runtime.RecognizerSharedState = function() {
9    /** Track the set of token types that can follow any rule invocation.
10     *  Stack grows upwards.  When it hits the max, it grows 2x in size
11     *  and keeps going.
12     */
13    this.following = [];
14
15    this._fsp = -1;
16
17    /** This is true when we see an error and before having successfully
18     *  matched a token.  Prevents generation of more than one error message
19     *  per error.
20     */
21    this.errorRecovery = false;
22
23    /** The index into the input stream where the last error occurred.
24     *  This is used to prevent infinite loops where an error is found
25     *  but no token is consumed during recovery...another error is found,
26     *  ad naseum.  This is a failsafe mechanism to guarantee that at least
27     *  one token/tree node is consumed for two errors.
28     */
29    this.lastErrorIndex = -1;
30
31    /** In lieu of a return value, this indicates that a rule or token
32     *  has failed to match.  Reset to false upon valid token match.
33     */
34    this.failed = false;
35
36    /** Did the recognizer encounter a syntax error?  Track how many. */
37    this.syntaxErrors = 0;
38
39    /** If 0, no backtracking is going on.  Safe to exec actions etc...
40     *  If >0 then it's the level of backtracking.
41     */
42    this.backtracking = 0;
43
44    /** An array[size num rules] of Map<Integer,Integer> that tracks
45     *  the stop token index for each rule.  ruleMemo[ruleIndex] is
46     *  the memoization table for ruleIndex.  For key ruleStartIndex, you
47     *  get back the stop token for associated rule or MEMO_RULE_FAILED.
48     *
49     *  This is only used if rule memoization is on (which it is by default).
50     */
51    this.ruleMemo = null;
52
53
54    // LEXER FIELDS (must be in same state object to avoid casting
55    //               constantly in generated code and Lexer object) :(
56
57
58    /** The goal of all lexer rules/methods is to create a token object.
59     *  This is an instance variable as multiple rules may collaborate to
60     *  create a single token.  nextToken will return this object after
61     *  matching lexer rule(s).  If you subclass to allow multiple token
62     *  emissions, then set this to the last token to be matched or
63     *  something nonnull so that the auto token emit mechanism will not
64     *  emit another token.
65     */
66    this.token = null;
67
68    /** What character index in the stream did the current token start at?
69     *  Needed, for example, to get the text for current token.  Set at
70     *  the start of nextToken.
71     */
72    this.tokenStartCharIndex = -1;
73
74    /** The line on which the first character of the token resides */
75    // this.tokenStartLine;
76
77    /** The character position of first character within the line */
78    // this.tokenStartCharPositionInLine;
79
80    /** The channel number for the current token */
81    // this.channel;
82
83    /** The token type for the current token */
84    // this.type;
85
86    /** You can set the text for the current token to override what is in
87     *  the input char buffer.  Use setText() or can set this instance var.
88     */
89    this.text = null;
90};
91