braden has asked for the wisdom of the Perl Monks concerning the following question:

Using Parse::RecDescent, is it possible to access skipped text (i.e., text skipped because of a <skip> directive)?

I'd like to parse doc-comments in code and it occurs to me that a convenient way to do this would be to grab the skipped text and perform additional parsing on it. Alternatively I suppose I'm looking at littering my grammar with all the places comments can occur (just about anywhere).

Replies are listed 'Best First'.
Re: Parse::RecDescent: access "skipped" text?
by ikegami (Patriarch) on Apr 11, 2006 at 15:23 UTC
    No, nor does it make any sense. Where would you store the extracted info? Storing it in a global won't work because it will survive backtracking. Maybe if we knew more about what you are trying to do, we could help you better.
      As I mentioned, I'm trying to parse code (like C or C++ or Java) with doc-comments (like javadoc or doxygen). I'm interested in the doc-comments, so I don't want to just throw them away.

      Without some way to parse text that is notionally “skipped” (that is, as far as the “real” grammar—that of the programming language—is concerned), I realize I'm looking at injecting comments into the programming language grammar as additional productions. But since comments can occur anywhere that whitespace can, this is going to get verbose. So I was looking for a Better Way.

Re: Parse::RecDescent: access "skipped" text?
by santonegro (Scribe) on Apr 11, 2006 at 18:46 UTC
      That may indeed be useful to me; thanks.

      However, it still looks like I'm looking at littering my grammar with all the places comments can occur.

      It may be that I'm thinking about this wrong in trying to parse code and comments in a single pass with the same parser. The Right Thing may be to parse code in one pass and doc-comments in another.