[antlr-interest] handling /// comments

ajk . anders43 at gmail.com
Sat Sep 20 21:38:32 PDT 2008


On Fri, Sep 19, 2008 at 10:47 PM, Johannes Luber <jaluber at gmx.de> wrote:

> ajk . schrieb:
> > Hi
> >
> > I was wondering if somebody has an idea how to solve the following
> > problem. Lets see if I can describe the issue in a proper way.
> >
> > We have a translator that translates a scripting language to C#.
> >
> > We now need to support ///<summary>.. in C#
> >
> > By adding the /// in the scripting language we were hoping just to move
> > this over to C#:
> >
> > example
> >
> > /// <summary>
> > /// some function
> > /// </summary>
> > myfunction returns int
> > begin
> >    bla();
> > end
> >
> > ->
> >
> > C#
> > /// <summary>
> > /// some function
> > /// </summary>
> > int myfunction()
> > {
> >   bla();
> > }
> >
> > So far so good, I would associate the comments to the following function
> > which is a node in the AST, simple to do a parser rule for this.
> >
> > But in C# (as well as the scripting language) you can write comments
> > anywhere in the code in whatever form you want e.g.
> >
> > /// hello
> >
> > or
> >
> > ///////////////////////////////////////////
> > //// this freestanding comment
> > ////////////////////////////////////////////
> >
> > How do you filter away these things? How do I write a parser rule that
> > allows comments anywhere in the original code but only move the relevant
> > ones? i.e. the ones associated with certain elements like functions,
> > variable declarations etc.
> >
> > TIA
> > Anders.
>
> There are two possible ways to solve this issue. The first is to add
> COMMENT nodes everywhere they may appear. But this reduces the
> readability a lot. The other way is to put off the COMMENT tokens
> off-channel and to scan in front of matched function definitions for a
> COMMENT token yourself.
>
> Johannes
>


The latter method sounds better, our language is very large so the less
changes to the grammar the better. In v2 (which I am not familiar with) how
to set tokens to come into the hidden channel? In v3 you just write
$Channel=HIDDEN right?

thanks
Anders.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080921/febc5bbe/attachment.html 


More information about the antlr-interest mailing list