forked from bartuer/ydiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff-scheme.ss
104 lines (73 loc) · 2.66 KB
/
diff-scheme.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;; ydiff - a language-aware tool for comparing programs
;; Copyright (C) 2011 Yin Wang ([email protected])
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(load "parse-scheme.ss")
(load "diff.ss")
;-------------------------------------------------------------
; overrides
;-------------------------------------------------------------
(define *keywords*
'(define defun defvar lambda cond if else
let let* let-values let*-values
while for define-syntax syntax-rules
define-minor-mode))
(define *defs*
'(define defun defvar define-syntax define-minor-mode))
;; helper for get-type
(define get-keyword
(lambda (node)
(match node
[(Expr _ _ type elts)
(cond
[(null? elts) #f]
[else
(let ([sym (get-symbol (car elts))])
(cond
[(memq sym *keywords*) sym]
[else #f]))])]
[_ #f])))
; (get-keyword (car (parse-scheme "(defvar f 1)")))
;; We need to override get-type because
;; S-expression-based languages are flexible about their
;; syntax and don't have rigid types attached to their AST
;; nodes.
;; override
(define get-type
(lambda (node)
(cond
[(Expr? node)
(get-keyword node)]
[(Token? node) 'token]
[(Comment? node) 'comment]
[(Str? node) 'str]
[(Char? node) 'char])))
;; override
(define get-name
(lambda (node)
(let ([key (get-keyword node)])
(cond
[(and key (memq key *defs*))
(get-symbol (cadr (Expr-elts node)))]
[else #f]))))
;; (same-def? (car (parse-scheme "(define f 1)"))
;; (car (parse-scheme "(define f 1)")))
;; (different-def? (car (parse-scheme "(define f 1)"))
;; (car (parse-scheme "(define g 1)")))
;-----------------------------------------
(define diff-scheme
(lambda (file1 file2)
(load "diff-scheme.ss")
(diff file1 file2 parse-scheme)))
; (diff-scheme "tests/paredit20.el" "tests/paredit22.el")
; (diff-scheme "tests/mk.scm" "tests/mk-c.scm")
; (diff-scheme "tests/pass1.ss" "tests/pass2.ss")
; (diff-scheme "parse-js.ss" "parse-cpp.ss")