[antlr-interest] Parsing comments

Soren Holstebroe holstebroe at gmail.com
Thu Sep 17 07:55:20 PDT 2009


Hi,

I have this project where C++ templates are being unfolded and wrapped in
.NET. This wrapping is performed by some perl-scripts which over time have
become quite messy, so I wanted to rewrite the wrapper using ANTLR.

The way the current template wrapper works is by parsing simple template
expressions defined in the comments preceding a function definition. This is
similar to documentation frameworks like doxygen, where the documentation is
embedded in the comments above functions, classes, etc.
The simple syntax contains elements like this:
// @TEMPLATE <int, float>
which tells the wrapper to unfold the template using an int for the first
template type and a float for the second.

My problem is that I am already stuck in defining the lexer.
Since all wrapper expressions start with '@' I tried to define a token like:
WRAPPERSTART : SLASHSLASH SPACE* '@'
and some grammar rules based on that token.
However that doesn't work since the lexer will always choose the longest
matching rule, which would always be the normal single line comment rule.

I can imagine that there are many approaches to tackle this problem and some
hints would be greatly appreciated.

Soren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090917/4a8bdd79/attachment.html 


More information about the antlr-interest mailing list