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