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  */
32 namespace Antlr.Runtime
33 {
34 
35     /** <summary>A stream of tokens accessing tokens from a TokenSource</summary> */
36     public interface ITokenStream : IIntStream
37     {
38         /** <summary>Get Token at current input pointer + i ahead where i=1 is next Token.
39          *  i&lt;0 indicates tokens in the past.  So -1 is previous token and -2 is
40          *  two tokens ago. LT(0) is undefined.  For i&gt;=n, return Token.EOFToken.
41          *  Return null for LT(0) and any index that results in an absolute address
42          *  that is negative.</summary>
43          */
LT( int k )44         IToken LT( int k );
45 
46         /// <summary>
47         /// How far ahead has the stream been asked to look?  The return
48         /// value is a valid index from 0..n-1.
49         /// </summary>
50         int Range
51         {
52             get;
53         }
54 
55         /** <summary>
56          *  Get a token at an absolute index i; 0..n-1.  This is really only
57          *  needed for profiling and debugging and token stream rewriting.
58          *  If you don't want to buffer up tokens, then this method makes no
59          *  sense for you.  Naturally you can't use the rewrite stream feature.
60          *  I believe DebugTokenStream can easily be altered to not use
61          *  this method, removing the dependency.
62          *  </summary>
63          */
Get( int i )64         IToken Get( int i );
65 
66         /** <summary>
67          *  Where is this stream pulling tokens from?  This is not the name, but
68          *  the object that provides Token objects.
69          *  </summary>
70          */
71         ITokenSource TokenSource
72         {
73             get;
74         }
75 
76         /** <summary>
77          *  Return the text of all tokens from start to stop, inclusive.
78          *  If the stream does not buffer all the tokens then it can just
79          *  return "" or null;  Users should not access $ruleLabel.text in
80          *  an action of course in that case.
81          *  </summary>
82          */
ToString( int start, int stop )83         string ToString( int start, int stop );
84 
85         /** <summary>
86          *  Because the user is not required to use a token with an index stored
87          *  in it, we must provide a means for two token objects themselves to
88          *  indicate the start/end location.  Most often this will just delegate
89          *  to the other toString(int,int).  This is also parallel with
90          *  the TreeNodeStream.toString(Object,Object).
91          *  </summary>
92          */
ToString( IToken start, IToken stop )93         string ToString( IToken start, IToken stop );
94     }
95 }
96