tree-sitter / tree-sitter-ruby

Ruby grammar for tree-sitter
MIT License
176 stars 58 forks source link

Fix `!=` operator definition #264

Closed stac47 closed 3 weeks ago

stac47 commented 1 month ago

Problem: If a class declare the not-equal operator !=, the parsing is wrong. For instance, the folowing program:

class A
  def !=(other); end
end

is parsed as if the method ! was a defined with the body expression syntax leading to the following tree:

(program [0, 0] - [3, 0]
  (class [0, 0] - [1, 20]
    name: (constant [0, 6] - [0, 7])
    body: (body_statement [1, 2] - [1, 16]
      (method [1, 2] - [1, 15]
        name: (operator [1, 6] - [1, 7])
        body: (parenthesized_statements [1, 8] - [1, 15]
          (identifier [1, 9] - [1, 14])))))
  (identifier [2, 0] - [2, 3]))

Solution: Declare != as a possible operator definition.

Solves #174