Home | History | Annotate | Download | only in Runtime
      1 package ANTLR::Runtime::Token;
      2 
      3 use Readonly;
      4 
      5 use feature qw( state );
      6 
      7 use ANTLR::Runtime::CharStream;
      8 #use ANTLR::Runtime::CommonToken;
      9 
     10 use Moose::Role;
     11 
     12 Readonly my $EOR_TOKEN_TYPE => 1;
     13 sub EOR_TOKEN_TYPE { $EOR_TOKEN_TYPE }
     14 
     15 # imaginary tree navigation type; traverse "get child" link
     16 Readonly my $DOWN => 2;
     17 sub DOWN { $DOWN }
     18 
     19 # imaginary tree navigation type; finish with a child list
     20 Readonly my $UP => 3;
     21 sub UP { $UP }
     22 
     23 Readonly my $MIN_TOKEN_TYPE => $UP + 1;
     24 sub 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.
     29 Readonly my $DEFAULT_CHANNEL => 0;
     30 sub DEFAULT_CHANNEL { $DEFAULT_CHANNEL }
     31 
     32 # Anything on different channel than DEFAULT_CHANNEL is not parsed
     33 # by parser.
     34 Readonly my $HIDDEN_CHANNEL => 99;
     35 sub HIDDEN_CHANNEL { $HIDDEN_CHANNEL }
     36 
     37 sub EOF { ANTLR::Runtime::CharStream->EOF }
     38 
     39 #Readonly my $EOF_TOKEN => ANTLR::Runtime::CommonToken->new({ type => EOF });
     40 sub EOF_TOKEN {
     41     require ANTLR::Runtime::CommonToken;
     42     state $EOF_TOKEN = ANTLR::Runtime::CommonToken->new({ type => EOF });
     43     return $EOF_TOKEN;
     44 }
     45 
     46 Readonly my $INVALID_TOKEN_TYPE => 0;
     47 sub INVALID_TOKEN_TYPE { $INVALID_TOKEN_TYPE }
     48 
     49 #Readonly my $INVALID_TOKEN => ANTLR::Runtime::CommonToken->new({ type => INVALID_TOKEN_TYPE });
     50 sub 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 });
     59 sub 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 
     65 requires 'get_text', 'set_text';
     66 
     67 requires 'get_type', 'set_type';
     68 
     69 requires 'get_line', 'set_line';
     70 
     71 requires 'get_char_position_in_line', 'set_char_position_in_line';
     72 
     73 requires 'get_channel', 'set_channel';
     74 
     75 requires 'get_token_index', 'set_token_index';
     76 
     77 requires 'get_input_stream', 'set_input_stream';
     78 
     79 no Moose::Role;
     80 1;
     81