[antlr-interest] import construct - parsing each module once
Jeroen van Schagen
jeroen.v.schagen at gmail.com
Thu Aug 20 13:45:45 PDT 2009
The language I'm currently implementing contains import constructs. So far
I've used the standard import implementation from the ANTLR wiki which goes:
import: 'import' moduleId -> 'import' moduleId ^( {
parseFile($moduleId.path) } ) ;
However this implementation will hang on circular dependancies and reduce my
parser performance when having multiple imports to the same module. So I
decided to keep a list of all the modules I've parsed so far, meaning I only
have to parse each module once. This has resulted in the following
implementation:
imprt: 'import' moduleId {
if(! modules.contains($moduleId.path)) {
Object dependancy = adaptor.becomeRoot(parseFile($moduleId.path), (Object)
adaptor.nil());
adaptor.addChild(root_0, dependancy);
}
}
@member { CommonTree parseFile(String path) { ... } }
The implementation works, however I would like a cleaner solution,
preferably using a rewrite rule. Any suggestions?
Thanks in advance!
Jeroen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090820/dc3ac7f6/attachment.html
More information about the antlr-interest
mailing list