tree-sitter-c icon indicating copy to clipboard operation
tree-sitter-c copied to clipboard

Distinguish between line and block comments

Open nacl opened this issue 2 years ago • 1 comments

The current grammar does not distinguish between line comment and block comments. Supporting this would make it more convenient for editors to see in what type of comment they are in, and then make formatting decisions without examining the code themselves.

FWIW, the Java grammar (which has the same comment syntax as C and C++), does this already. Something similar could easily be done here (there's already a skeleton for it). See also https://github.com/tree-sitter/tree-sitter-java/issues/92

nacl avatar Nov 09 '23 02:11 nacl

There is a strong convention across lots of parsers to use one comment node for all kinds of comments. Use cases that need to distinguish between comment types can use queries and #match? predicates.

You're right thattree-sitter-java does things differently, but it's the exception, and I'm honestly pretty surprised that that change got landed. (A later proposal to distinguish JavaDoc comments was closed under the “use queries instead” rationale.)

I think it's worth having a philosophical discussion about. I'd be just as happy to have different line_comment and block_comment types for all languages, but I'd much rather have a uniform pattern across all parsers.

savetheclocktower avatar Jan 09 '24 00:01 savetheclocktower