[antlr-interest] Javadoc style parsing

Adam Connelly adam.rpconnelly at googlemail.com
Wed Jan 2 17:33:27 PST 2008


Thanks for the reply.

I'll check out that paper you mentioned if I get a chance.  I think I'll
follow your advice and make the comments part of the grammar.  I think what
I'll do is have comments that are just ignored by the parser (C/C++ style
comments), then have a separate comment style for holding the descriptions
that's only allowed in certain places.  Probably easier that way in the long
run.  I guess it also means that I can give some structure to the comments
to hold different types of information.

Cheers,

Adam

On Jan 3, 2008 12:35 AM, Andy Tripp <antlr at jazillian.com> wrote:

> Adam Connelly wrote:
> > Hi,
> >
> > Just wanted to ask for some ideas.  I'm designing a language and have
> > most of the grammar done (I've still to add a few bits in and put in
> > the template generation).  The language is a modeling language for
> > describing some database objects and I'd like to allow some meta-data
> > to hold a human friendly description of these objects.
> >
> > I had an idea of having a special type of comment (like in javadoc)
> > that I would send to a different channel than the standard parser.  I
> > could then parse these comments separately (although this might not
> > end up being desirable).  This would mean that I wouldn't have to put
> > in references to an optional comment rule wherever comments were
> allowed.
> >
> > The downside to this that I can see at the moment is that I'm not sure
> > how I would then get the information about the object that each
> > comment was attached to.
> >
> > Any ideas?
> >
> > Adam
> The hard part is associating each comment with a particular node in the
> AST. Peter Van Der Ahe at Sun wrote a
> good paper about how hard that is, and even that paper only scratched
> the surface.
>
> Consider this code:
> ----------------------------------------
> // here is a comment that appears to be at the top of the file, but only
> because there are a few blank lines after it.
>
> // a comment that seems to "go with" the following line, and not the
> previous comment, but again, only because of blank lines
> int i;
>
> for (int i=0; i<10 /* what does any inline comment go with? */; i++)
>   // a comment that "goes with" the block inside the for loop
>  {
>      // another comment that "goes with" the block inside the for loop
>  }  // does this comment "go with" the for loop, or the following code?
> ----------------------------------------
>
> If you have control of the language (sounds like you do), I'd seriously
> consider making comments a real part of the grammar,
> perhaps having a "comment statement", as opposed to the C, C++, Java,
> and many other languages approach of
> allowing statements anywhere and having a preprocessor throw them out.
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080103/06102019/attachment.html 


More information about the antlr-interest mailing list