[antlr-interest] Sub-Lexers?

Natan nvivo.misc at gmail.com
Mon Aug 17 19:59:07 PDT 2009


C. Mundi wrote:
> What I'm thinking is a lexer which finds the clauses followed by a
> parser which does a trivial rewrite which embeds actions to invoke
> specialized lexers for each clause type.  All of the specialized
> levers target a single AST which is handled by a unified parser.
>   
I once found this in the wiki while looking for ways to parse 
placeholders in strings:

http://www.antlr.org/wiki/display/ANTLR3/Island+Grammars+Under+Parser+Control

But in my case I found this to be too complicated for my needs, and I 
choose to create a new filter lexer, and do the parsing later in the 
code in a method. I just needed some info for replacements, so I created 
a method in the AST node that did the lexing and return a collection of 
objects for me.

I see that in your case, you are looking for a full grammar, but anyway, 
it helps to remember you don't need to do everything in one step. If the 
grammars are that much different, you can do a 2 step pass in the code: 
parse the basics and divide the grammars like they were really different 
files, and then get the list from the parser and call a different parser 
depending on the input.

Of course, someone here with more experience may have a better solution. =)

[]'s


More information about the antlr-interest mailing list