1/*
2 [The "BSD license"]
3 Copyright (c) 2005-2009 Terence Parr
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 1. Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12     notice, this list of conditions and the following disclaimer in the
13     documentation and/or other materials provided with the distribution.
14 3. The name of the author may not be used to endorse or promote products
15     derived from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28package org.antlr.runtime;
29
30import java.util.List;
31
32/** A stream of tokens accessing tokens from a TokenSource */
33public interface TokenStream extends IntStream {
34    /** Get Token at current input pointer + i ahead where i=1 is next Token.
35	 *  i<0 indicates tokens in the past.  So -1 is previous token and -2 is
36	 *  two tokens ago. LT(0) is undefined.  For i>=n, return Token.EOFToken.
37	 *  Return null for LT(0) and any index that results in an absolute address
38	 *  that is negative.
39	 */
40    public Token LT(int k);
41
42	/** How far ahead has the stream been asked to look?  The return
43	 *  value is a valid index from 0..n-1.
44	 */
45	int range();
46
47	/** Get a token at an absolute index i; 0..n-1.  This is really only
48	 *  needed for profiling and debugging and token stream rewriting.
49	 *  If you don't want to buffer up tokens, then this method makes no
50	 *  sense for you.  Naturally you can't use the rewrite stream feature.
51	 *  I believe DebugTokenStream can easily be altered to not use
52	 *  this method, removing the dependency.
53	 */
54	public Token get(int i);
55
56	/** Where is this stream pulling tokens from?  This is not the name, but
57	 *  the object that provides Token objects.
58	 */
59	public TokenSource getTokenSource();
60
61	/** Return the text of all tokens from start to stop, inclusive.
62	 *  If the stream does not buffer all the tokens then it can just
63	 *  return "" or null;  Users should not access $ruleLabel.text in
64	 *  an action of course in that case.
65	 */
66	public String toString(int start, int stop);
67
68	/** Because the user is not required to use a token with an index stored
69	 *  in it, we must provide a means for two token objects themselves to
70	 *  indicate the start/end location.  Most often this will just delegate
71	 *  to the other toString(int,int).  This is also parallel with
72	 *  the TreeNodeStream.toString(Object,Object).
73	 */
74	public String toString(Token start, Token stop);
75}
76