[antlr-interest] How to implement a "require" mechanism?
Sébastien Mosser
sebastien.mosser at gmail.com
Mon Nov 15 04:44:27 PST 2010
Le 12 nov. 2010 à 18:36, Michael Matera a écrit :
> Hi Sebastien,
>
> There's an ANTLR wiki entry that shows how to do this:
>
>> http://www.antlr.org/wiki/pages/viewpage.action?pageId=557057
>
> It works by inserting tokens into your token stream which has the effect
> of generating an AST at the point of the require.
The last code snippet perfectly fits my need. It's a shame that I don't use the "include" keyword when I googled my problem.
However, another simple question: How to handle properly cyclic inclusions? I basically use a "visitedFile" table declared as a parser member. When I start the 'sub-parser', I set its visited table to the current one. And after the end of the sub-parse, I set mine to the one available in the sub-parser.
Is there another solution? Mine looks like a hack :S
Cheers,
--
Sébastien Mosser
http://sebastien-mosser.fr
More information about the antlr-interest
mailing list