[antlr-interest] Re: lexer "modes" for XML parsing etc...

Oliver Zeigermann oliver.zeigermann at gmail.com
Sun Nov 20 21:49:44 PST 2005


2005/11/20, Terence Parr <parrt at cs.usfca.edu>:
> Your wish is my command.  ;)  Do we need something like
>
> lexer grammar L;
>
> ID : ... ;
> SQLSTART : "sql(" {pushContext(SQL);} ;
> WS : ... ;
>
> context SQL {
> ID : ... ;
> ACTION : ...;
> STRING : ... ;
> ENDSQL : ')' {popContext();}
> }
>
> context island2 {
> ...
> }
>
> [note the push/pop rather than simple set; very useful]
>
> Then, the lexer would simply generate multiple Tokens-like rules for
> all contexts?  You see a different lexer entry rule for each
> context.  How do you switch?  We'd need an int constant (as we have
> no function poitners in Java--a pox on their family) that would jump
> to the right starting method.
>
> Sounds easy.  Is this what we want?  It is proper for island grammars
> that feed off the same input stream.  Multiple input streams like
> include files need to be handled with a multiplexing input buffer.

That's what I would like to see.

Oliver


More information about the antlr-interest mailing list