treesitter

Resolve conflict in tree-sitter grammar


I want to create code with only identifiers and couple symbols like

identifier

identifier = identifier

identifier = identifier 

identifier 

identifier = identifier

identifier = identifier

Identifier by it own is a start of group and name of this group, identifiers with symbols are items of group, so output tree should be like

document
  group
    name
    formula 
    formula
  group
    name
    formula 
    formula 

I wrote basic grammar, but tree-sitter throws error

Unresolved conflict for symbol sequence:

  identifier _nl_eof  •  identifier  …

Possible interpretations:

  1:  (group identifier _nl_eof  •  group_repeat1)
  2:  (group identifier _nl_eof)  •  identifier  …

Possible resolutions:

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

Can please someone help me with this?


Solution

  • Just added conflicts: $ => [[$.group]] and everything fixes magically