[antlr-interest] Mini language embedded in language. How to?

Marcin Rzeźnicki marcin.rzeznicki at gmail.com
Fri Feb 19 05:03:08 PST 2010


Hi all,
I am looking for a clean ANTLR way to parse a language which is embedded in
another language. Let's assume that we have parser for a language which
enables name aliasing. The syntax for such operation is:
ID ALIAS "alias"

Also, there are slightly different rules governing aliases, they can be more
than ordinary identifiers, for example:
distance alias "|-|" ( where |-| is not a valid identifier)

So, clearly, I have to write another parser/lexer for this "alias language",
which I did actually; to avoid breaking DRY rule I made it dependent on
"main" lexer and so on - and that is fine.

So, under conditions I described above, what is the best way to operate this
'slave' parser. I'd like to: start the other parser in appropriate rule
(probably an action) so that it parser next input. If 'slave' reports syntax
error, I'd like to have it propagated to the main parser client. If slave
thinks that alias syntax is ok, then let it emit the appropriate token and
pass the control back to the main parser which then resumes scanning where
'slave' has left. I appreciate hearing about your ideas. Thanks.




-- 
Greetings
Marcin Rzeźnicki


More information about the antlr-interest mailing list