[antlr-interest] ignoring lexer rules

Sinan sinan.karasu at boeing.com
Wed Mar 6 09:51:50 PST 2002

Ed Sinjiashvili wrote:
> Hi,
> I've tried to ask Terence about this issue and he pointed me to this
> ML. So here I am. Suppose I have the following grammar(that describes
> literal strings with escaped octal numbers inside):

I would do something like:

import antlr.*;

public class MyTokenStreamSelector extends TokenStreamSelector {
	/** The set of token types to discard */

	public MyTokenStreamSelector() {

	public Token nextToken() throws TokenStreamException {
			try {
				Token tok = super.nextToken();

					//code to replace the octal stuff maybe regular expressions.

				return tok;
			catch (TokenStreamRetryException r) {
				// just retry "forever"

And then in your MyParser.g

	private MyTokenStreamSelector filter=null;
	public MyParser(MyTokenStreamSelector lexer) {

and where you instantiate Parser/Lexer etc....

 public static MyTokenStreamSelector selector = new

// notify selector about starting lexer; name for convenience
		selector.addInputStream(myMainLexer, "main");
		selector.select("main"); // start with main P lexer

		// Create a parser that reads from the scanner
		myParser = new MyParser(selector);


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list