13447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein/*
23447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein [The "BSD license"]
33447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein Copyright (c) 2005-2009 Terence Parr
43447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein All rights reserved.
53447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
63447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein Redistribution and use in source and binary forms, with or without
73447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein modification, are permitted provided that the following conditions
83447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein are met:
93447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein 1. Redistributions of source code must retain the above copyright
103447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     notice, this list of conditions and the following disclaimer.
113447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein 2. Redistributions in binary form must reproduce the above copyright
123447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     notice, this list of conditions and the following disclaimer in the
133447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     documentation and/or other materials provided with the distribution.
143447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein 3. The name of the author may not be used to endorse or promote products
153447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     derived from this software without specific prior written permission.
163447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
173447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
183447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
203447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
213447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
263447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein */
283447a5916aa62f44de24cc441fc9987116ddff52Andrew Sappersteinpackage org.antlr.runtime;
293447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
303447a5916aa62f44de24cc441fc9987116ddff52Andrew Sappersteinimport java.util.List;
313447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
323447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein/** A stream of tokens accessing tokens from a TokenSource */
333447a5916aa62f44de24cc441fc9987116ddff52Andrew Sappersteinpublic interface TokenStream extends IntStream {
343447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein    /** Get Token at current input pointer + i ahead where i=1 is next Token.
353447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  i<0 indicates tokens in the past.  So -1 is previous token and -2 is
363447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  two tokens ago. LT(0) is undefined.  For i>=n, return Token.EOFToken.
373447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  Return null for LT(0) and any index that results in an absolute address
383447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  that is negative.
393447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
403447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein    public Token LT(int k);
413447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
423447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** How far ahead has the stream been asked to look?  The return
433447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  value is a valid index from 0..n-1.
443447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
453447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	int range();
463447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
473447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** Get a token at an absolute index i; 0..n-1.  This is really only
483447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  needed for profiling and debugging and token stream rewriting.
493447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  If you don't want to buffer up tokens, then this method makes no
503447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  sense for you.  Naturally you can't use the rewrite stream feature.
513447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  I believe DebugTokenStream can easily be altered to not use
523447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  this method, removing the dependency.
533447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
543447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public Token get(int i);
553447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
563447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** Where is this stream pulling tokens from?  This is not the name, but
573447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  the object that provides Token objects.
583447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
593447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public TokenSource getTokenSource();
603447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
613447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** Return the text of all tokens from start to stop, inclusive.
623447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  If the stream does not buffer all the tokens then it can just
633447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  return "" or null;  Users should not access $ruleLabel.text in
643447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  an action of course in that case.
653447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
663447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public String toString(int start, int stop);
673447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
683447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** Because the user is not required to use a token with an index stored
693447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  in it, we must provide a means for two token objects themselves to
703447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  indicate the start/end location.  Most often this will just delegate
713447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  to the other toString(int,int).  This is also parallel with
723447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  the TreeNodeStream.toString(Object,Object).
733447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
743447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public String toString(Token start, Token stop);
753447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein}
76