1 module antlr.v4.runtime.TokenSource;
2 
3 import antlr.v4.runtime.CharStream;
4 import antlr.v4.runtime.Token;
5 import antlr.v4.runtime.CommonToken;
6 import antlr.v4.runtime.TokenFactory;
7 
8 // Interface TokenSource
9 /**
10  * TODO add interface description
11  */
12 interface TokenSource
13 {
14 
15     /**
16      * @uml
17      * Get the index into the current line for the current position in the input
18      *  stream. The first character on a line has position 0.
19      *
20      *  @return The line number for the current position in the input stream, or
21      * -1 if the current token source does not track character positions.
22      */
23     public int getCharPositionInLine();
24 
25     /**
26      * @uml
27      * Return a {@link Token} object from your input stream (usually a
28      *  {@link CharStream}). Do not fail/return upon lexing error; keep chewing
29      * on the characters until you get a good one; errors are not passed through
30      * to the parser.
31      */
32     public Token nextToken();
33 
34     /**
35      * @uml
36      * Get the line number for the current position in the input stream. The
37      * first line in the input is line 1.
38      *
39      *  @return The line number for the current position in the input stream, or
40      * 0 if the current token source does not track line numbers.
41      */
42     public int getLine();
43 
44     /**
45      * @uml
46      * Get the {@link CharStream} from which this token source is currently
47      * providing tokens.
48      *
49      *  @return The {@link CharStream} associated with the current position in
50      * the input, or {@code null} if no input stream is available for the token
51      * source.
52      */
53     public CharStream getInputStream();
54 
55     /**
56      * @uml
57      * Gets the name of the underlying input source. This method returns a
58      * non-null, non-empty string. If such a name is not known, this method
59      * returns {@link IntStream#UNKNOWN_SOURCE_NAME}.
60      */
61     public string getSourceName();
62 
63     /**
64      * @uml
65      * Set the {@link TokenFactory} this token source should use for creating
66      * {@link Token} objects from the input.
67      *
68      *  @param factory The {@link TokenFactory} to use for creating tokens.
69      */
70     public void tokenFactory(TokenFactory!CommonToken factory);
71 
72     /**
73      * @uml
74      * Gets the {@link TokenFactory} this token source is currently using for
75      * creating {@link Token} objects from the input.
76      *
77      *  @return The {@link TokenFactory} currently used by this token source.
78      */
79     public TokenFactory!CommonToken tokenFactory();
80 
81 }