• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 [The "BSD licence"]
3 Copyright (c) 2007-2008 Johannes Luber
4 Copyright (c) 2005-2007 Kunle Odutola
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10 1. Redistributions of source code MUST RETAIN the above copyright
11    notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form MUST REPRODUCE the above copyright
13    notice, this list of conditions and the following disclaimer in
14    the documentation and/or other materials provided with the
15    distribution.
16 3. The name of the author may not be used to endorse or promote products
17    derived from this software without specific prior WRITTEN permission.
18 4. Unless explicitly state otherwise, any contribution intentionally
19    submitted for inclusion in this work to the copyright owner or licensor
20    shall be under the terms and conditions of this license, without any
21    additional terms or conditions.
22 
23 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 
36 namespace Antlr.Runtime
37 {
38 	using System;
39 
40 	/// <summary>
41 	/// A source of tokens must provide a sequence of tokens via NextToken()
42 	/// and also must reveal it's source of characters; CommonToken's text is
43 	/// computed from a CharStream; it only store indices into the char stream.
44 	///
45 	/// Errors from the lexer are never passed to the parser.  Either you want
46 	/// to keep going or you do not upon token recognition error.  If you do not
47 	/// want to continue lexing then you do not want to continue parsing.  Just
48 	/// throw an exception not under RecognitionException and Java will naturally
49 	/// toss you all the way out of the recognizers.  If you want to continue
50 	/// lexing then you should not throw an exception to the parser--it has already
51 	/// requested a token.  Keep lexing until you get a valid one.  Just report
52 	/// errors and keep going, looking for a valid token.
53 	/// </summary>
54 	public interface ITokenSource
55 	{
56 		/// <summary>
57 		/// Returns a Token object from the input stream (usually a CharStream).
58 		/// Does not fail/return upon lexing error; just keeps chewing on the
59 		/// characters until it gets a good one; errors are not passed through
60 		/// to the parser.
61 		/// </summary>
NextToken()62 		IToken NextToken();
63 
64 		/// <summary>
65 		/// Where are you getting tokens from? normally the implication will simply
66 		/// ask lexers input stream.
67 		/// </summary>
68 		string SourceName {
69 			get;
70 		}
71 	}
72 }