Re: Comment skipper or first class member of grammar

Seth <[email protected]> Mon, 24 Dec 2018 02:02:21 +0100
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Op 17-12-18 om 05:30 schreef Michael Powell:
> I can see there potentially being
> some value in capturing the comments and carrying them forward with
> the target language adapter.

You'll have to be the architect of your requirements/specifications. If
you want to carry over comments, be very specific about which types you
want to support/carry over and how. If you allow for them in the middle
of declarations, how will you deal with them when the target grammar
doesn't have a similar syntactical structure?

It seems pretty obvious to me that your "longua franca" or "document
object model" here is Protobuf itself: messages, services, enums and
fields. You carry these 1:1 on one, not input tokens.

I would probably suggest to "harvest" all inline comments and
concatenate all of them into a trailing comments that "belongs to" the
declaration it follows (or appeared as part of). That way you preserve
the contents but not necessarily all placement (which should be
non-meaningful, or they wouldn't be _comments_, much like you *can* but
*should not* use XML comments to convey out-of-schema content, or why
official JSON doesn't even have comments etc.)

It's not really that hard of a decision to make once you get the
thinking clear.

Seth