1*37748cd8SNickeau<?php 2*37748cd8SNickeau 3*37748cd8SNickeaudeclare(strict_types=1); 4*37748cd8SNickeau 5*37748cd8SNickeaunamespace Antlr\Antlr4\Runtime; 6*37748cd8SNickeau 7*37748cd8SNickeau/** 8*37748cd8SNickeau * A token has properties: text, type, line, character position in the line 9*37748cd8SNickeau * (so we can ignore tabs), token channel, index, and source from which 10*37748cd8SNickeau * we obtained this token. 11*37748cd8SNickeau */ 12*37748cd8SNickeauinterface Token 13*37748cd8SNickeau{ 14*37748cd8SNickeau public const INVALID_TYPE = 0; 15*37748cd8SNickeau 16*37748cd8SNickeau /** 17*37748cd8SNickeau * During lookahead operations, this `token` signifies we hit 18*37748cd8SNickeau * rule end ATN state and did not follow it despite needing to. 19*37748cd8SNickeau */ 20*37748cd8SNickeau public const EPSILON = -2; 21*37748cd8SNickeau 22*37748cd8SNickeau public const MIN_USER_TOKEN_TYPE = 1; 23*37748cd8SNickeau 24*37748cd8SNickeau public const EOF = IntStream::EOF; 25*37748cd8SNickeau 26*37748cd8SNickeau /** 27*37748cd8SNickeau * All tokens go to the parser (unless skip() is called in that rule) 28*37748cd8SNickeau * on a particular "channel". The parser tunes to a particular channel 29*37748cd8SNickeau * so that whitespace etc... can go to the parser on a "hidden" channel. 30*37748cd8SNickeau */ 31*37748cd8SNickeau public const DEFAULT_CHANNEL = 0; 32*37748cd8SNickeau 33*37748cd8SNickeau /** 34*37748cd8SNickeau * Anything on different channel than DEFAULT_CHANNEL is not parsed by parser. 35*37748cd8SNickeau */ 36*37748cd8SNickeau public const HIDDEN_CHANNEL = 1; 37*37748cd8SNickeau 38*37748cd8SNickeau /** 39*37748cd8SNickeau * This is the minimum constant value which can be assigned to 40*37748cd8SNickeau * a user-defined token channel. 41*37748cd8SNickeau * 42*37748cd8SNickeau * The non-negative numbers less than {@see Token::MIN_USER_CHANNEL_VALUE} 43*37748cd8SNickeau * are assigned to the predefined channels {@see Token::DEFAULT_CHANNEL} and 44*37748cd8SNickeau * {@see Token::HIDDEN_CHANNEL}. 45*37748cd8SNickeau * 46*37748cd8SNickeau * @see Token::getChannel() 47*37748cd8SNickeau */ 48*37748cd8SNickeau public const MIN_USER_CHANNEL_VALUE = 2; 49*37748cd8SNickeau 50*37748cd8SNickeau /** 51*37748cd8SNickeau * Get the text of the token. 52*37748cd8SNickeau */ 53*37748cd8SNickeau public function getText() : ?string; 54*37748cd8SNickeau 55*37748cd8SNickeau /** 56*37748cd8SNickeau * Get the token type of the token. 57*37748cd8SNickeau */ 58*37748cd8SNickeau public function getType() : int; 59*37748cd8SNickeau 60*37748cd8SNickeau /** 61*37748cd8SNickeau * The line number on which the 1st character of this token was matched, line = 1..n 62*37748cd8SNickeau */ 63*37748cd8SNickeau public function getLine() : int; 64*37748cd8SNickeau 65*37748cd8SNickeau /** 66*37748cd8SNickeau * The index of the first character of this token relative to the beginning 67*37748cd8SNickeau * of the line at which it occurs, 0..n-1 68*37748cd8SNickeau */ 69*37748cd8SNickeau public function getCharPositionInLine() : int; 70*37748cd8SNickeau 71*37748cd8SNickeau /** 72*37748cd8SNickeau * Return the channel this token. Each token can arrive at the parser 73*37748cd8SNickeau * on a different channel, but the parser only "tunes" to a single channel. 74*37748cd8SNickeau * The parser ignores everything not on DEFAULT_CHANNEL. 75*37748cd8SNickeau */ 76*37748cd8SNickeau public function getChannel() : int; 77*37748cd8SNickeau 78*37748cd8SNickeau /** 79*37748cd8SNickeau * An index from 0..n-1 of the token object in the input stream. This must 80*37748cd8SNickeau * be valid in order to print token streams and use TokenRewriteStream. 81*37748cd8SNickeau * 82*37748cd8SNickeau * Return -1 to indicate that this token was conjured up since 83*37748cd8SNickeau * it doesn't have a valid index. 84*37748cd8SNickeau */ 85*37748cd8SNickeau public function getTokenIndex() : int; 86*37748cd8SNickeau 87*37748cd8SNickeau /** 88*37748cd8SNickeau * The starting character index of the token. 89*37748cd8SNickeau * This method is optional; return -1 if not implemented. 90*37748cd8SNickeau */ 91*37748cd8SNickeau public function getStartIndex() : int; 92*37748cd8SNickeau 93*37748cd8SNickeau /** 94*37748cd8SNickeau * The last character index of the token. 95*37748cd8SNickeau * This method is optional; return -1 if not implemented. 96*37748cd8SNickeau */ 97*37748cd8SNickeau public function getStopIndex() : int; 98*37748cd8SNickeau 99*37748cd8SNickeau /** 100*37748cd8SNickeau * Gets the {@see TokenSource} which created this token. 101*37748cd8SNickeau */ 102*37748cd8SNickeau public function getTokenSource() : ?TokenSource; 103*37748cd8SNickeau 104*37748cd8SNickeau /** 105*37748cd8SNickeau * Gets the {@see CharStream} from which this token was derived. 106*37748cd8SNickeau */ 107*37748cd8SNickeau public function getInputStream() : ?CharStream; 108*37748cd8SNickeau 109*37748cd8SNickeau public function __toString(); 110*37748cd8SNickeau} 111