[antlr-interest] Changing lexers mid-stream

Dennis Sosnoski dms at sosnoski.com
Tue Jan 11 23:44:30 PST 2011


I'm wondering if there's an easy way to switch back and forth between
different lexers while processing a stream. I'm working with Java
language documents, and I'd like to be able to break down /**...*/
comments into components - but to do this, I'd need to switch modes when
I enter the start of a comment, and switch back to normal Java lexer
rules at the end of the comment.

Any ideas?

I can do this in my own code, breaking down the comments into different
types of tokens that become part of the token stream - but that's
basically just writing my own lexer, which seems kind of silly.

  - Dennis



More information about the antlr-interest mailing list