tree-sitter-haskell icon indicating copy to clipboard operation
tree-sitter-haskell copied to clipboard

Incorrect parse for function with where-clause and comments

Open wenkokke opened this issue 1 year ago • 11 comments

When parsing a function with a where-clause, tree-sitter-haskell groups comments after the where-clause into the decls node, rather than making them top-level comment nodes. For instance, the following code:

foo = bar
  where
    bar = 1
--   🎉 `foo = bar` and `bar = 1`
--   👀 `foo = bar where bar = 1`
--   🚀 `foo = bar where bar = 1` and `bar = 1`

bap :: Int -> Int
bap | 1 == 1, 2 == 2 = x
--   🎉 `1 == 1` and `2 == 2`
--   👀 `1 == 1, 2 == 2`

Parses to the following tree:

(haskell
  (function
    name: (variable)
    "="
    rhs: (exp_name
      (variable)
    )
    (where)
    (decls
      (function
        name: (variable)
        "="
        rhs: (exp_literal
          (integer)
        )
      )
      (comment)
      (comment)
      (comment)
    )
  )
  (signature
    name: (variable)
    type: "::"
    type: (fun
      (type_name
        (type)
      )
      "->"
      (type_name
        (type)
      )
    )
  )
  (function
    name: (variable)
    (guard_equation
      (guards
        "|"
        (guard
          (exp_infix
            (exp_literal
              (integer)
            )
            (operator)
            (exp_literal
              (integer)
            )
          )
        )
        (comma)
        (guard
          (exp_infix
            (exp_literal
              (integer)
            )
            (operator)
            (exp_literal
              (integer)
            )
          )
        )
      )
      "="
      (exp_name
        (variable)
      )
    )
  )
  (comment)
  (comment)
)

wenkokke avatar Jan 18 '24 21:01 wenkokke