ladderlife / autochrome

Structural diffs for clojure source code
Eclipse Public License 1.0
186 stars 11 forks source link

autochrome as library #5

Closed edvorg closed 6 years ago

edvorg commented 6 years ago

hi is there way to separate html related functionality and the core alogrithm in order to integrate this to diff tool? e.g. emacs ediff

fazzone commented 6 years ago

It's definitely possible. The annotations get attached to the AST which might look like this:

{:type :coll
  :delim \(
  :annotation :parens-added
  :contents [{:type :symbol :text "foo" :annotation :added}
             {:type :symbol :text "unchanged"}]}

You can get something like that to play around with in a repl like this:

(let [old (parse/parse-one "[:a :b :c]")
      new (parse/parse-one "[:a :x :b :y :c :z]")
      ann (diff/diff-forms old [new])]
  (annotation/attach new ann))

It would be pretty easy to tweak the existing render function to do something with them (and also render the original whitespace). The difficult part would be that the way to report the diff annotations is probably different for different tools. I'm not sure that anyone writing such a diff tool would have expected this sort of thing so it could be tricky.

edvorg commented 6 years ago

Thank you for pointing out, I'll look into it!

fazzone commented 6 years ago

I added a render-dup function myself here. The idea is that for any input string s, s = (render-dup (parse s)) (otherwise it's a bug). might make this easier.