[antlr-interest] Rewinding the token stream between templates
Kirk Woods
woods.kirk at gmail.com
Tue Dec 12 13:15:52 PST 2006
I am in the process of creating a tool, with ANTLR 3.0b5 and StringTemplate
3.0, which at this point has two template files and will most likely have
four in the future. After parsing with the first template group, I must
rewind the token stream in order to parse with the next template group.
parser.setTemplateLib(Main.createTemplates);
RuleReturnScope ruleScope = parser.program();
System.out.println(ruleScope.getTemplate().toString());
parser.getTokenStream().rewind(0);
parser.setTemplateLib(Main.alterTemplates);
ruleScope = parser.program();
System.out.println(ruleScope.getTemplate().toString());
While I can do this by calling "parser.getTokenStream().rewind(0)", this
creates a dependency on knowledge of the internal implementation of the
parser. I would like to suggest that the implementation of the
setTemplateLib method be modified to rewind the token stream (e.g.
super.input.rewind(-1)). Is there a valid use case where one would not want
the token stream reset whenever the setTemplateLib method is called?
Thanks,
Kirk Woods
p.s. These are great tools. I have only been using these for two weeks and
the amount of code I am now able to generate is tremendous.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061212/e1879375/attachment.html
More information about the antlr-interest
mailing list