1 package ANTLR::Runtime::RecognizerSharedState; 2 3 use ANTLR::Runtime::Token; 4 5 use Moose; 6 7 # Track the set of token types that can follow any rule invocation. 8 # Stack grows upwards. When it hits the max, it grows 2x in size 9 # and keeps going. 10 has 'following' => ( 11 is => 'rw', 12 isa => 'ArrayRef[ANTLR::Runtime::BitSet]', 13 default => sub { [] }, 14 ); 15 16 has '_fsp' => ( 17 is => 'rw', 18 isa => 'Int', 19 default => -1, 20 ); 21 22 # This is true when we see an error and before having successfully 23 # matched a token. Prevents generation of more than one error message 24 # per error. 25 has 'error_recovery' => ( 26 is => 'rw', 27 isa => 'Bool', 28 default => 0, 29 ); 30 31 # The index into the input stream where the last error occurred. 32 # This is used to prevent infinite loops where an error is found 33 # but no token is consumed during recovery...another error is found, 34 # ad naseum. This is a failsafe mechanism to guarantee that at least 35 # one token/tree node is consumed for two errors. 36 has 'last_error_index' => ( 37 is => 'rw', 38 isa => 'Int', 39 default => -1, 40 ); 41 42 # In lieu of a return value, this indicates that a rule or token 43 # has failed to match. Reset to false upon valid token match. 44 has 'failed' => ( 45 is => 'rw', 46 isa => 'Bool', 47 default => 0, 48 ); 49 50 # Did the recognizer encounter a syntax error? Track how many. 51 has 'syntax_errors' => ( 52 is => 'rw', 53 isa => 'Int', 54 default => 0, 55 ); 56 57 # If 0, no backtracking is going on. Safe to exec actions etc... 58 # If >0 then it's the level of backtracking. 59 has 'backtracking' => ( 60 is => 'rw', 61 isa => 'Int', 62 default => 0, 63 ); 64 65 # An array[size num rules] of Map<Integer,Integer> that tracks 66 # the stop token index for each rule. ruleMemo[ruleIndex] is 67 # the memoization table for ruleIndex. For key ruleStartIndex, you 68 # get back the stop token for associated rule or MEMO_RULE_FAILED. 69 # This is only used if rule memoization is on (which it is by default). 70 has 'rule_memo' => ( 71 is => 'rw', 72 isa => 'Maybe[ArrayRef[HashRef[Int]]]', 73 ); 74 75 # The goal of all lexer rules/methods is to create a token object. 76 # This is an instance variable as multiple rules may collaborate to 77 # create a single token. nextToken will return this object after 78 # matching lexer rule(s). If you subclass to allow multiple token 79 # emissions, then set this to the last token to be matched or 80 # something nonnull so that the auto token emit mechanism will not 81 # emit another token. 82 has 'token' => ( 83 is => 'rw', 84 isa => 'Maybe[ANTLR::Runtime::Token]', 85 ); 86 87 # What character index in the stream did the current token start at? 88 # Needed, for example, to get the text for current token. Set at 89 # the start of nextToken. 90 has 'token_start_char_index' => ( 91 is => 'rw', 92 isa => 'Int', 93 default => -1, 94 ); 95 96 # The line on which the first character of the token resides 97 has 'token_start_line' => ( 98 is => 'rw', 99 isa => 'Int', 100 ); 101 102 # The character position of first character within the line 103 has 'token_start_char_position_in_line' => ( 104 is => 'rw', 105 isa => 'Int', 106 ); 107 108 # The channel number for the current token 109 has 'channel' => ( 110 is => 'rw', 111 isa => 'Int', 112 ); 113 114 # The token type for the current token 115 has 'type' => ( 116 is => 'rw', 117 isa => 'Int', 118 ); 119 120 # You can set the text for the current token to override what is in 121 # the input char buffer. Use setText() or can set this instance var. 122 has 'text' => ( 123 is => 'rw', 124 isa => 'Maybe[Str]', 125 ); 126 127 no Moose; 128 __PACKAGE__->meta->make_immutable(); 129 1; 130 __END__ 131