1e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson/*
2e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson [The "BSD license"]
3e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson Copyright (c) 2005-2009 Terence Parr
4e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson All rights reserved.
5e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson
6e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson Redistribution and use in source and binary forms, with or without
7e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson modification, are permitted provided that the following conditions
8e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson are met:
9e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson 1. Redistributions of source code must retain the above copyright
10e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson     notice, this list of conditions and the following disclaimer.
11e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson 2. Redistributions in binary form must reproduce the above copyright
12e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson     notice, this list of conditions and the following disclaimer in the
13e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson     documentation and/or other materials provided with the distribution.
14e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson 3. The name of the author may not be used to endorse or promote products
15e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson     derived from this software without specific prior written permission.
16e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson
17e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson */
28e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinsonpackage org.antlr.runtime;
29e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson
30e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7Ian Parkinson/** A source of tokens must provide a sequence of tokens via nextToken()
31 *  and also must reveal it's source of characters; CommonToken's text is
32 *  computed from a CharStream; it only store indices into the char stream.
33 *
34 *  Errors from the lexer are never passed to the parser.  Either you want
35 *  to keep going or you do not upon token recognition error.  If you do not
36 *  want to continue lexing then you do not want to continue parsing.  Just
37 *  throw an exception not under RecognitionException and Java will naturally
38 *  toss you all the way out of the recognizers.  If you want to continue
39 *  lexing then you should not throw an exception to the parser--it has already
40 *  requested a token.  Keep lexing until you get a valid one.  Just report
41 *  errors and keep going, looking for a valid token.
42 */
43public interface TokenSource {
44	/** Return a Token object from your input stream (usually a CharStream).
45	 *  Do not fail/return upon lexing error; keep chewing on the characters
46	 *  until you get a good one; errors are not passed through to the parser.
47	 */
48	public Token nextToken();
49
50	/** Where are you getting tokens from? normally the implication will simply
51	 *  ask lexers input stream.
52	 */
53	public String getSourceName();
54}
55