Skip to content

Commit 76d3a7d

Browse files
committed
recreate repo
0 parents  commit 76d3a7d

File tree

6 files changed

+2928
-0
lines changed

6 files changed

+2928
-0
lines changed

demos/demo1.py

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
##################################################################
2+
# Demo for an AST-based diffing tool
3+
# author: Yin Wang ([email protected])
4+
##################################################################
5+
6+
##################################################################
7+
# Features:
8+
# - Detect insertion, deletion and modification of code
9+
# - Detect refactoring (renamed or moved code)
10+
# - Assess similarity of code
11+
# - Ignore comments and whitespaces
12+
#
13+
###################################################################
14+
# Usage:
15+
#
16+
# - Mouseover any framed elements to show information
17+
#
18+
# - Click on Blue or White elements to match the other side.
19+
# Once matched, the two sides will be locked into that
20+
# position until next match.
21+
#
22+
####################################################################
23+
# Legend of colors:
24+
#
25+
# - Red : deleted
26+
# - Green : inserted
27+
# - Blue : modified (mouse over to show percentage of change)
28+
# - White : unchanged or moved
29+
#
30+
###################################################################
31+
32+
33+
34+
35+
class Nil:
36+
def __repr__(this):
37+
return "()"
38+
39+
nil = Nil() # singleton instance of Nil
40+
41+
42+
43+
class Cons:
44+
def __init__(this, first, rest):
45+
this.first = first
46+
this.rest = rest
47+
def __repr__(this):
48+
if (this.rest == nil):
49+
return "(" + repr(this.first) + ")"
50+
elif (IS(this.rest, Cons)):
51+
s = repr(this.rest)
52+
return "(" + repr(this.first) + " " + s[1:-1] + ")"
53+
else:
54+
return "(" + repr(this.first) + " . " + repr(this.rest) + ")"
55+
56+
57+
58+
59+
def foldl(f, x, ls):
60+
if ls == nil:
61+
return x
62+
else:
63+
return foldl(f, f(x, ls.first), ls.rest)
64+
65+
66+
67+
68+
def length(ls):
69+
if ls == nil:
70+
return 0
71+
else:
72+
return 1 + length(ls.rest)
73+
74+
75+
76+
77+
def atomAssoc(u, v):
78+
return Cons(Cons(u, v), nil)
79+
80+
81+
82+
83+
def mkList(pylist):
84+
if (pylist == []):
85+
return nil
86+
else:
87+
return Cons(pylist[0], mkList(pylist[1:]))
88+
89+
90+
91+
92+
def toList(ls):
93+
ret = []
94+
while ls <> nil:
95+
ret.append(ls.first)
96+
ls = ls.rest
97+
return ret
98+
99+
100+
101+
102+
def ext(x, v, s):
103+
return Cons(Cons(x, v), s)
104+
105+
106+
107+
108+
def append(ls1, ls2):
109+
if (ls1 == nil):
110+
return ls2
111+
else:
112+
return append(ls1.rest, Cons(ls1.first, ls2))
113+
114+
115+
116+
117+
def assq(x, s):
118+
while s <> nil:
119+
if x == s.first.first:
120+
return s.first
121+
else:
122+
s = s.rest
123+
return None
124+
125+
# if (s == nil):
126+
# return None
127+
# elif (x == s.first.first):
128+
# return s.first
129+
# else:
130+
# return assq(x, s.rest)
131+
132+
133+
# lookup is unchanged, but it is moved in relative
134+
# position to other functions.
135+
def lookup(x, s):
136+
p = assq(x, s)
137+
if p <> None:
138+
return p.snd
139+
else:
140+
return None
141+
142+
143+
144+
# cmap was renamed to maplist, but the function
145+
# has been modified significantly since renaming.
146+
# Thus we no longer consider them to be the same
147+
# function.
148+
def cmap(f, ls):
149+
if (ls == nil):
150+
return nil
151+
else:
152+
return Cons(f(ls.first), cmap(f, ls.rest))
153+
154+
155+
# reverse is unchanged
156+
def reverse(ls):
157+
ret = nil
158+
while ls <> nil:
159+
ret = Cons(ls.first, ret)
160+
ls = ls.rest
161+
return ret
162+
163+
164+
165+
# cfilter was renamed to filterlist, but the
166+
# function has been modified significantly since
167+
# renaming. Thus we no longer consider them to be
168+
# the same function.
169+
def cfilter(f, ls):
170+
ret = nil
171+
while ls <> nil:
172+
if f(ls.first):
173+
ret = Cons(ls.first, ret)
174+
ls = ls.rest
175+
return reverse(ret)
176+
177+
# if (ls == nil):
178+
# return nil
179+
# elif f(ls.first):
180+
# return Cons(ls.first, cfilter(f, ls.rest))
181+
# else:
182+
# return cfilter(f, ls.rest)
183+

demos/demo2.py

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
##################################################################
2+
# Demo for an AST-based diffing tool
3+
# author: Yin Wang ([email protected])
4+
##################################################################
5+
6+
##################################################################
7+
# Features:
8+
# - Detect insertion, deletion and modification of code
9+
# - Detect refactoring (renamed or moved code)
10+
# - Assess similarity of code
11+
# - Ignore comments and whitespaces
12+
#
13+
###################################################################
14+
# Usage:
15+
#
16+
# - Mouseover any framed elements to show information
17+
#
18+
# - Click on Blue or White elements to match the other side.
19+
# Once matched, the two sides will be locked into that
20+
# position until next match.
21+
#
22+
####################################################################
23+
# Legend of colors:
24+
#
25+
# - Red : deleted
26+
# - Green : inserted
27+
# - Blue : modified (mouse over to show percentage of change)
28+
# - White : unchanged or moved
29+
#
30+
###################################################################
31+
32+
33+
34+
35+
36+
class PairIterator:
37+
def __init__(self, p):
38+
self.p = p
39+
def next(self):
40+
if self.p == nil:
41+
raise StopIteration
42+
ret = self.p.fst
43+
self.p = self.p.snd
44+
return ret
45+
46+
47+
48+
49+
class Nil:
50+
def __repr__(self):
51+
return "()"
52+
def __iter__(self):
53+
return PairIterator(self)
54+
55+
nil = Nil() # singleton instance of Nil
56+
57+
58+
59+
60+
class Pair:
61+
def __init__(self, fst, snd):
62+
self.fst = fst
63+
self.snd = snd
64+
def __repr__(self):
65+
if (self.snd == nil):
66+
return "(" + repr(self.fst) + ")"
67+
elif (isinstance(self.snd, Pair)):
68+
s = repr(self.snd)
69+
return "(" + repr(self.fst) + " " + s[1:-1] + ")"
70+
else:
71+
return "(" + repr(self.fst) + " . " + repr(self.snd) + ")"
72+
def __iter__(self):
73+
return PairIterator(self)
74+
75+
76+
77+
78+
def foldl(f, x, ls):
79+
ret = x
80+
for y in ls:
81+
ret = f(ret, y)
82+
return ret
83+
84+
85+
86+
87+
def length(ls):
88+
ret = 0
89+
for x in ls:
90+
ret = ret + 1
91+
return ret
92+
93+
94+
95+
96+
def assoc(u, v):
97+
return Pair(Pair(u, v), nil)
98+
99+
100+
101+
102+
def slist(pylist):
103+
ret = nil
104+
for i in xrange(len(pylist)):
105+
ret = Pair(pylist[len(pylist)-i-1], ret)
106+
return ret
107+
108+
109+
110+
111+
def pylist(ls):
112+
ret = []
113+
for x in ls:
114+
ret.append(x)
115+
return ret
116+
117+
118+
119+
# maplist was renamed from cmap, but the function
120+
# has been modified significantly since renaming.
121+
# Thus we no longer consider them to be the same
122+
# function.
123+
def maplist(f, ls):
124+
ret = nil
125+
for x in ls:
126+
ret = Pair(f(x), ret)
127+
return reverse(ret)
128+
129+
130+
131+
# filterlist was renamed from cfilter, but the
132+
# function has been modified significantly since
133+
# renaming. Thus we no longer consider them to be
134+
# the same function.
135+
def filterlist(f, ls):
136+
ret = nil
137+
for x in ls:
138+
if f(x):
139+
ret = Pair(x, ret)
140+
return reverse(ret)
141+
142+
143+
144+
def reverse(ls):
145+
ret = nil
146+
while ls <> nil:
147+
ret = Cons(ls.first, ret)
148+
ls = ls.rest
149+
return ret
150+
151+
# def reverse(ls):
152+
# ret = nil
153+
# for x in ls:
154+
# ret = Pair(x, ret)
155+
# return ret
156+
157+
158+
159+
160+
def append(*lists, **kw):
161+
def append1(ls1, ls2):
162+
ret = ls2
163+
for x in ls1:
164+
ret = Pair(x, ret)
165+
return ret
166+
return foldl(append1, nil, slist(lists))
167+
168+
169+
170+
171+
def assq(x, s):
172+
for p in s:
173+
if x == p.fst:
174+
return p
175+
return None
176+
177+
178+
179+
180+
def ziplist(ls1, ls2):
181+
ret = nil
182+
while ls1 <> nil and ls2 <> nil:
183+
ret = Pair(Pair(ls1.fst, ls2.fst), ret)
184+
ls1 = ls1.snd
185+
ls2 = ls2.snd
186+
return reverse(ret)
187+
188+
189+
190+
191+
# building association lists
192+
def ext(x, v, s):
193+
return Pair(Pair(x, v), s)
194+
195+
196+
197+
198+
def lookup(x, s):
199+
p = assq(x, s)
200+
if p <> None:
201+
return p.snd
202+
else:
203+
return None
204+
205+

0 commit comments

Comments
 (0)