4 ms·
There are various tools for this: I believe one of the interns at Jane Street wrote a tool to diff s-expressions, and similar tools exist for lisp source code.
by fiddlerwoaroof 6y ago
There are various tools for this: I believe one of the interns at Jane Street wrote a tool to diff s-expressions, and similar tools exist for lisp source code. Ultimately, the issue is that tooling is mostly made to be programming-language independent, which makes it hard for this sort of tooling to succeed
- ulrikrasmussen 6y agoI think making a tool like that language independent is impossible. You have to start by making it a diff tool just for tree structured data (diff tools today are special cases of this as they operate on list based data). You then need to extend it to work on specific languages by diffing "modulo equations", e.g. in Haskell two top-level definitions are allowed to commute, so `x = e; y = f` should be considered identical to `y = f; x = e`. But I think that's fine. The diff tool should use the most specific diff mode that it knows is safe, and fall back to the "free diff" of tree structured data when working on an unknown language.
- fiddlerwoaroof 6y agoI looked into using tree-sitter as a bar for this once: parse code into an AST of sorts and then use the ast to define the diff boundaries. Didn’t think through all the problems, though