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