tree-sitter / tree-sitter-haskell

Haskell grammar for tree-sitter.
MIT License
151 stars 36 forks source link

Include . from qualified modules and variables #102

Closed Wilfred closed 3 months ago

Wilfred commented 1 year ago

Given the file:

import System.Process

The parse tree is:

haskell (0, 0) - (1, 0)
  import (0, 0) - (0, 21)
    import (0, 0) - (0, 6) "import"
    qualified_module (0, 7) - (0, 21)
      module (0, 7) - (0, 13) "System"
      module (0, 14) - (0, 21) "Process"

There's no node for ., which makes life harder for AST tools like difftastic.

tek commented 1 year ago

hmm is that due to the fact that the dot is parsed by the scanner? Would you have the same problem with literal terminals, i.e. if it was a plain '.' in the javascript grammar?

Wilfred commented 1 year ago

I can't highlight the . if it's not in the AST, so I end up with weird diffs. I have a workaround in place that flattens the parent AST node, but it's not ideal.

For comparison, foo.bar parses as this in JS:

program (0, 0) - (1, 0)
  expression_statement (0, 0) - (0, 7)
    member_expression (0, 0) - (0, 7)
      identifier (0, 0) - (0, 3) "foo"
      . (0, 3) - (0, 4) "."
      property_identifier (0, 4) - (0, 7) "bar"
tek commented 1 year ago

ah, can I get the CLI to display text nodes like in your snippet?

Wilfred commented 11 months ago

I don't know of any way to display this from the tree-sitter CLI I'm afraid. The output above is dumped from difftastic with difft --dump-ts foo.hs.

tek commented 6 months ago

@Wilfred I lifted your printing code and ran it against my current development efforts, can you confirm that this is the desired structure:

haskell (0, 0) - (0, 12)
  import (0, 0) - (0, 12)
    import (0, 0) - (0, 6) "import"
    qualified_module (0, 7) - (0, 12)
      module (0, 7) - (0, 8) "A"
      . (0, 8) - (0, 9) "."
      module (0, 9) - (0, 10) "A"
      . (0, 10) - (0, 11) "."
      module (0, 11) - (0, 12) "A"
Wilfred commented 6 months ago

@tek that looks great to me! :)