[antlr-interest] How to implement a "require" mechanism?
Sébastien Mosser
sebastien.mosser at gmail.com
Fri Nov 12 07:47:07 PST 2010
Hi,
This is my first post on this mailing list. so let's start by a little presentation. I'm a French young researcher (aka 'postdoc'), working on the definition of mechanisms to support separation of concerns approaches.
I'm currently using ANTLR & StringTemplate to implement a translator associated to a prototype. By the way, these two tools are impressive (I previously only work with ANTLR for another project).
However, I'm encountering a (big) issue. The translator I'm designing must support the definition of a "require" mechanism. A source file "x" must be able to require the content of another source file "y".
The translator first start by building an AST, and then a tree grammar visit the AST and use the appropriate templates. My first idea is to implement something like the following snippet in the grammar:
require: 'require' fileName=STRING ';' {
build the AST associated to $fileName;
insert its content inside the current one;
}
however, I have no idea on how to implement the second actions, that is, including the content of another AST into this one. I'm not even sure this is the right solution to my problem :'(. Is preprocessing a better solution?
Any ideas?
Cheers,
--
Sébastien
More information about the antlr-interest
mailing list