sexp-diff
sexp-diff
7.7

sexp-diff

Vincent St-Amour <stamourv@racket-lang.org>

This package provides an S-expression-aware diffing tool based on Levenshtein-like tree edit distance.

procedure

(sexp-diff e1    
  e2    
  [#:old-marker old-marker    
  #:new-marker new-marker])  sexp?
  e1 : sexp?
  e2 : sexp?
  old-marker : any/c = '#:old
  new-marker : any/c = '#:new
Produces a tree that corresponds to the common structure of e1 and e2, with e1-specific parts tagged with old-marker and e2-specific parts tagged with new-marker.

Examples:
> (sexp-diff
   '(define (f x) (+ (* x 2) 1))
   '(define (f x) (- (* x 2) 3 1)))

'((define (f x) (#:new - #:old + (* x 2) #:new 3 1)))

> (sexp-diff
   '(define (f x) (+ (* x 2) 4 1))
   '(define (f x) (- (* x 2) 5 3 1)))

'((define (f x) (#:new - #:old + (* x 2) #:new 5 #:new 3 #:old 4 1)))

> (sexp-diff
   '(define (f x) (+ (* x 2) 4 4 1))
   '(define (f x) (- (* x 2) 5 5 3 1)))

'((define (f x)

    (#:new - #:old + (* x 2) #:new 5 #:new 5 #:new 3 #:old 4 #:old 4 1)))

> (sexp-diff
   #:old-marker '#:expected #:new-marker '#:actual
   '(1 2 3 4)
   '(1 2 2 4))

'((1 #:actual 2 2 #:expected 3 4))