Question: Is it possible to have control over comments while having them in extras? #2186
-
Hi, I maintain a tree-sitter grammar for terraform and got the following issue: tree-sitter-grammars/tree-sitter-hcl#30. I wrote the grammar in a way that comments are part of the Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You'd have to make the body node start before the comment. Currently it looks like you have the body node start at baz. You could, for example, move the open/close curly braces inside the body definition. |
Beta Was this translation helpful? Give feedback.
-
It's not possible cause the body may be empty and dangling curles in the body would look weird instead of absent body node. Technically for parser the situation is correct because the body node isn't started right after the open curly and that means there are no tokens that belong to the body. @MichaHoffmann I've opened a PR tree-sitter-grammars/tree-sitter-hcl#31 that demonstrates how to cheat Tree-sitter parser with a fake token. |
Beta Was this translation helpful? Give feedback.
It's not possible cause the body may be empty and dangling curles in the body would look weird instead of absent body node.
Technically for parser the situation is correct because the body node isn't started right after the open curly and that means there are no tokens that belong to the body.
@MichaHoffmann I've opened a PR tree-sitter-grammars/tree-sitter-hcl#31 that demonstrates how to cheat Tree-sitter parser with a fake token.
Screenshot