[antlr-interest] How to pass-through comments and complete sentences in ANTLR3.1
Chris Sekszczynska
Development at ChrisSek.de
Sat Oct 25 03:56:15 PDT 2008
Hi all,
while I familiarize myself with ANTLR to translate from one high-level
language to another, I wasn't able to find a good starting point showing
how to pass-through stuff from the input stream to templates.
Can someone give me a little hint? I'm using the latest version of
ANTLR to generate ASTs for an input stream. With the latest version of
StringTemplate I'm generating code from the AST using templates.
Concretely, I must retain stuff of the input stream in the following
situations:
1) Single line comments must be kept while parsing
2) Multi line comments must also be kept but have to be converted
into
Single line comments
3) If a parsing error occurred, the complete sentence of the input
stream (which produces the error) must passed into the AST to
write it into the resulting code. Moreover, ANTLR must continue
parsing when running into this situation.
I've already found Terence article at [1] but I'm not sure whether
this is
the best way under ANTLR3. As I'm writing comment into the hidden
channel,
it would be great to deal with this channels rather than modifying
ANTLR.
Is there a sophisticated solution for my three problems?
Thank you very much in advance.
Kind regards,
Chris Sekszczynska
Student of computer engineering
at University of Applied Sciences Bremen, Germany
[1] http://www.antlr.org/article/preserving.token.order/preserving.token.order.tml
More information about the antlr-interest
mailing list