tree-sitter / haskell-tree-sitter

Haskell bindings for tree-sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AST datatypes don’t support diffing

robrix opened this issue · comments

(Forked off of/supersedes #143.)

The TH code currently produces AST datatypes which don’t support diffing: we can’t e.g. replace a subterm with a diff of that subterm.

We will likely need to employ higher-kinded data, à la:

data If f a = If { ann :: a, condition :: f (Expr f a), consequence :: f (Stmt f a), alternative :: f (Stmt f a) }

Ordinary terms will then be represented by e.g. If Identity (tho I suspect we will wish to use type/pattern synonyms to improve the ergonomics of this), while we could represent possibly-missing/-ignored subterms with If Maybe. This would likewise allow some appropriately-configured Diff datatype to represent the term positions.

We might also need to move the responsibility for holding or applying the annotations into f to allow us to e.g. represent both original annotations for common nodes, but only one for deletions/insertions. We might need to use an even weirder kind to allow diffs to represent deletions/insertions of unchanged terms. Experimentation will be required