Skip to content

Incorrect parse for function with where-clause and comments  #109

Open
@wenkokke

Description

@wenkokke

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)
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions