[antlr-interest] Changing lexers mid-stream

Bart Kiers bkiers at gmail.com
Tue Jan 11 23:54:37 PST 2011


On Wed, Jan 12, 2011 at 8:44 AM, Dennis Sosnoski <dms at sosnoski.com> wrote:

> 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
>
>
Have you seen this:
http://www.antlr.org/wiki/display/ANTLR3/Island+Grammars+Under+Parser+Control
<http://www.antlr.org/wiki/display/ANTLR3/Island+Grammars+Under+Parser+Control>
?

Kind regards,

Bart.


More information about the antlr-interest mailing list