tree-sitter-grammars/tree-sitter-lua

Comment nodes substituted by string literals by mistake

Closed this issue · 3 comments

ahlinc commented

Screenshot from 2023-07-19 23-03-23

On the left side it's shown how comment nodes look in this grammar implementation, it would be better to represent them by simple non literal nodes like:

    // comment
    comment: ($) =>
      choice(
        seq(
          field('start', '--'), // I removed alias at all, because it's a bad practice to hide actual string literal tokens
          field('content', alias(/[^\r\n]*/, $.comment_content))
        ),
        seq(
          field('start', alias($._block_comment_start, $.comment_start)),
          field(
            'content',
            optional(alias($._block_comment_content, $.comment_content))
          ),
          field('end', alias($._block_comment_end, $.comment_end))
        )
      ),
  },

Just curious, does having named node provide any additional benefits here?

You've provided example from https://github.com/tjdevries/tree-sitter-lua, but I see that both parser do the same thing here.

Anyway, I've opened a PR to make comment node structured similar to string node: #37

ahlinc commented

Just curious, does having named node provide any additional benefits here?

It helps to avoid misunderstanding because anonymous nodes usually are used for a language syntax elements like braces, operators and so on.