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