01: /*
02: [The "BSD licence"]
03: Copyright (c) 2005-2006 Terence Parr
04: All rights reserved.
05:
06: Redistribution and use in source and binary forms, with or without
07: modification, are permitted provided that the following conditions
08: are met:
09: 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: */
28: package org.antlr.runtime;
29:
30: /** A stream of tokens accessing tokens from a TokenSource */
31: public interface TokenStream extends IntStream {
32: /** Get Token at current input pointer + i ahead where i=1 is next Token.
33: * i<0 indicates tokens in the past. So -1 is previous token and -2 is
34: * two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken.
35: * Return null for LT(0) and any index that results in an absolute address
36: * that is negative.
37: */
38: public Token LT(int k);
39:
40: /** Get a token at an absolute index i; 0..n-1. This is really only
41: * needed for profiling and debugging and token stream rewriting.
42: * If you don't want to buffer up tokens, then this method makes no
43: * sense for you. Naturally you can't use the rewrite stream feature.
44: * I believe DebugTokenStream can easily be altered to not use
45: * this method, removing the dependency.
46: */
47: public Token get(int i);
48:
49: /** Where is this stream pulling tokens from? This is not the name, but
50: * the object that provides Token objects.
51: */
52: public TokenSource getTokenSource();
53:
54: /** Return the text of all tokens from start to stop, inclusive.
55: * If the stream does not buffer all the tokens then it can just
56: * return "" or null; Users should not access $ruleLabel.text in
57: * an action of course in that case.
58: */
59: public String toString(int start, int stop);
60:
61: /** Because the user is not required to use a token with an index stored
62: * in it, we must provide a means for two token objects themselves to
63: * indicate the start/end location. Most often this will just delegate
64: * to the other toString(int,int). This is also parallel with
65: * the TreeNodeStream.toString(Object,Object).
66: */
67: public String toString(Token start, Token stop);
68: }
|