tree-sitter/tree-sitter-c

Distinguish between line and block comments

nacl opened this issue · 1 comments

nacl commented

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 tree-sitter/tree-sitter-java#92

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.