1 /*
2  * Copyright (c) 2012-2018 The ANTLR Project. All rights reserved.
3  * Use of this file is governed by the BSD 3-clause license that
4  * can be found in the LICENSE.txt file in the project root.
5  */
6 
7 module antlr.v4.runtime.Token;
8 
9 import antlr.v4.runtime.IntStream;
10 import antlr.v4.runtime.CharStream;
11 import antlr.v4.runtime.TokenSource;
12 
13 /**
14  * A token has properties: text, type, line, character position in the line
15  * (so we can ignore tabs), token channel, index, and source from which
16  * we obtained this token.
17  */
18 interface Token
19 {
20 
21     /**
22      * Get the text of the token.
23      */
24     public string getText();
25 
26     /**
27      * Get the token type of the token
28      */
29     public int getType();
30 
31     /**
32      * The line number on which the 1st character of this token was matched,
33      * line=1..n
34      */
35     public int getLine();
36 
37     /**
38      * The index of the first character of this token relative to the
39      * beginning of the line at which it occurs, 0..n-1
40      */
41     public int getCharPositionInLine();
42 
43     /**
44      * Return the channel this token. Each token can arrive at the parser
45      * on a different channel, but the parser only "tunes" to a single channel.
46      * The parser ignores everything not on DEFAULT_CHANNEL.
47      */
48     public int getChannel();
49 
50     /**
51      * An index from 0..n-1 of the token object in the input stream.
52      * This must be valid in order to print token streams and
53      * use TokenRewriteStream.
54      *
55      * Return -1 to indicate that this token was conjured up since
56      * it doesn't have a valid index.
57      */
58     public int getTokenIndex();
59 
60     /**
61      * The starting character index of the token
62      * This method is optional; return -1 if not implemented.
63      */
64     public int getStartIndex();
65 
66     /**
67      * The last character index of the token.
68      * This method is optional; return -1 if not implemented.
69      */
70     public int getStopIndex();
71 
72     /**
73      * Gets the {@link TokenSource} which created this token.
74      */
75     public TokenSource getTokenSource();
76 
77     /**
78      * Gets the {@link CharStream} from which this token was derived.
79      */
80     public CharStream getInputStream();
81 
82 }