TatSu icon indicating copy to clipboard operation
TatSu copied to clipboard

Cleanup recovery of grammar comments

Open apalala opened this issue 8 years ago • 1 comments

# comments retain the # and are output as (* *) comments.

Prettification of comments is not well defined.

It's best to stick to Python-style (#) comments.

apalala avatar May 07 '17 16:05 apalala

Comments can be added to the TatSu grammar for rule and option. The corresponding classes in grammars would have a comment field for the pretty-printer to use.

Some tweaks may be needed for comments right before a rule definition, and right after, before the first element.

PEG allows for this.

Complications would be on the pretty printer (most important), though the code generator could also try to do its part.

apalala avatar Mar 21 '21 20:03 apalala

The current design for attempting recovery of comments sucks!

This needs a better strategy, or deletion by giving grammar writers the responsibility for comment recovery.

apalala avatar Aug 20 '23 19:08 apalala

I dealt with this issue when parsing COBOL and NATURAL. I'm closing to think about it when I need to do something alike again. Not all grammars are easy when comment recovery is attempted.

I'd take a look at the new PEG Python grammar for Python.

My subconscious says that this would be manageable with tokenization, as was used in the PEG Python grammar, more so when now in TatSu Buffer is one implementation of Tokenizer.

This issue will come back. I just don't want to leave it open without a design, strategy, or pull request.

apalala avatar Aug 24 '23 19:08 apalala