1package ANTLR::Runtime::Token; 2 3use Readonly; 4 5use feature qw( state ); 6 7use ANTLR::Runtime::CharStream; 8#use ANTLR::Runtime::CommonToken; 9 10use Moose::Role; 11 12Readonly my $EOR_TOKEN_TYPE => 1; 13sub EOR_TOKEN_TYPE { $EOR_TOKEN_TYPE } 14 15# imaginary tree navigation type; traverse "get child" link 16Readonly my $DOWN => 2; 17sub DOWN { $DOWN } 18 19# imaginary tree navigation type; finish with a child list 20Readonly my $UP => 3; 21sub UP { $UP } 22 23Readonly my $MIN_TOKEN_TYPE => $UP + 1; 24sub MIN_TOKEN_TYPE { $MIN_TOKEN_TYPE } 25 26# All tokens go to the parser (unless skip() is called in that rule) 27# on a particular "channel". The parser tunes to a particular channel 28# so that whitespace etc... can go to the parser on a "hidden" channel. 29Readonly my $DEFAULT_CHANNEL => 0; 30sub DEFAULT_CHANNEL { $DEFAULT_CHANNEL } 31 32# Anything on different channel than DEFAULT_CHANNEL is not parsed 33# by parser. 34Readonly my $HIDDEN_CHANNEL => 99; 35sub HIDDEN_CHANNEL { $HIDDEN_CHANNEL } 36 37sub EOF { ANTLR::Runtime::CharStream->EOF } 38 39#Readonly my $EOF_TOKEN => ANTLR::Runtime::CommonToken->new({ type => EOF }); 40sub EOF_TOKEN { 41 require ANTLR::Runtime::CommonToken; 42 state $EOF_TOKEN = ANTLR::Runtime::CommonToken->new({ type => EOF }); 43 return $EOF_TOKEN; 44} 45 46Readonly my $INVALID_TOKEN_TYPE => 0; 47sub INVALID_TOKEN_TYPE { $INVALID_TOKEN_TYPE } 48 49#Readonly my $INVALID_TOKEN => ANTLR::Runtime::CommonToken->new({ type => INVALID_TOKEN_TYPE }); 50sub INVALID_TOKEN { 51 require ANTLR::Runtime::CommonToken; 52 state $INVALID_TOKEN = ANTLR::Runtime::CommonToken->new({ type => INVALID_TOKEN_TYPE }); 53 return $INVALID_TOKEN; 54} 55 56# In an action, a lexer rule can set token to this SKIP_TOKEN and ANTLR 57# will avoid creating a token for this symbol and try to fetch another. 58#Readonly my $SKIP_TOKEN => ANTLR::Runtime::CommonToken->new({ type => INVALID_TOKEN_TYPE }); 59sub SKIP_TOKEN { 60 require ANTLR::Runtime::CommonToken; 61 state $SKIP_TOKEN = ANTLR::Runtime::CommonToken->new({ type => INVALID_TOKEN_TYPE }); 62 return $SKIP_TOKEN; 63} 64 65requires 'get_text', 'set_text'; 66 67requires 'get_type', 'set_type'; 68 69requires 'get_line', 'set_line'; 70 71requires 'get_char_position_in_line', 'set_char_position_in_line'; 72 73requires 'get_channel', 'set_channel'; 74 75requires 'get_token_index', 'set_token_index'; 76 77requires 'get_input_stream', 'set_input_stream'; 78 79no Moose::Role; 801; 81