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