admin管理员组

文章数量:1125614

I'm currently implementing a custom grammar for a personal project using tree-sitter. Mostly everything is going alright, but I've run into a problem that I cannot wrap my head around.

Here's a simplified version of the situation that produces the same problem.

rule: $ => /[ab]+/
rule: $ => repeat1(choice("a","b"))

Now I must admit I'm not particularly well versed in the mathematics of grammars. I've gotten by mostly on intuition.

My intuition tells me these two statements are the same, though I must be missing something because tree-sitter says otherwise. The first implementation of rule with the regex passes with no complaints, but the second implementation produces the following error:

Unresolved conflict for symbol sequence:

  rule_repeat1  •  'a'  …

Possible interpretations:

  1:  (rule  rule_repeat1)  •  'a'  …
  2:  (rule_repeat1  rule_repeat1  •  rule_repeat1)

Possible resolutions:

  1:  Specify a left or right associativity in `rule`
  2:  Add a conflict for these rules: `rule`

Any help or explanation on what I've misunderstood would be greatly appreciated.

本文标签: neovimConfused on the difference between two treesitter grammar implementationsStack Overflow