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 import std.variant;
13 
14 /**
15  * A token has properties: text, type, line, character position in the line
16  * (so we can ignore tabs), token channel, index, and source from which
17  * we obtained this token.
18  */
19 interface Token
20 {
21 
22     /**
23      * Get the text of the token.
24      */
25     public Variant getText();
26 
27     /**
28      * Get the token type of the token
29      */
30     public int getType();
31 
32     /**
33      * The line number on which the 1st character of this token was matched,
34      * line=1..n
35      */
36     public int getLine();
37 
38     /**
39      * The index of the first character of this token relative to the
40      * beginning of the line at which it occurs, 0..n-1
41      */
42     public int getCharPositionInLine();
43 
44     /**
45      * Return the channel this token. Each token can arrive at the parser
46      * on a different channel, but the parser only "tunes" to a single channel.
47      * The parser ignores everything not on DEFAULT_CHANNEL.
48      */
49     public int getChannel();
50 
51     /**
52      * An index from 0..n-1 of the token object in the input stream.
53      * This must be valid in order to print token streams and
54      * use TokenRewriteStream.
55      *
56      * Return -1 to indicate that this token was conjured up since
57      * it doesn't have a valid index.
58      */
59     public size_t getTokenIndex();
60 
61     public size_t startIndex();
62 
63     public size_t stopIndex();
64 
65     /**
66      * Gets the {@link TokenSource} which created this token.
67      */
68     public TokenSource getTokenSource();
69 
70     /**
71      * Gets the {@link CharStream} from which this token was derived.
72      */
73     public CharStream getInputStream();
74 
75 }