Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<frameset cols="50%,50%"> | ||
<frame name="left" src="demo1.html"> | ||
<frame name="right" src="demo2.html"> | ||
</frameset> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
################################################################## | ||
# Demo for an AST-based diffing tool | ||
# author: Yin Wang (yinwang0@gmail.com) | ||
################################################################## | ||
|
||
################################################################## | ||
# Features: | ||
# - Detect insertion, deletion and modification of code | ||
# - Detect refactoring (renamed or moved code) | ||
# - Assess similarity of code | ||
# - Ignore comments and whitespaces | ||
# | ||
################################################################### | ||
# Usage: | ||
# | ||
# - Mouseover any framed elements to show information | ||
# | ||
# - Click on Blue or White elements to match the other side. | ||
# Once matched, the two sides will be locked into that | ||
# position until next match. | ||
# | ||
#################################################################### | ||
# Legend of colors: | ||
# | ||
# - Red : deleted | ||
# - Green : inserted | ||
# - Blue : modified (mouse over to show percentage of change) | ||
# - White : unchanged or moved | ||
# | ||
################################################################### | ||
|
||
|
||
|
||
|
||
class Nil: | ||
def __repr__(this): | ||
return "()" | ||
|
||
nil = Nil() # singleton instance of Nil | ||
|
||
|
||
|
||
class Cons: | ||
def __init__(this, first, rest): | ||
this.first = first | ||
this.rest = rest | ||
def __repr__(this): | ||
if (this.rest == nil): | ||
return "(" + repr(this.first) + ")" | ||
elif (IS(this.rest, Cons)): | ||
s = repr(this.rest) | ||
return "(" + repr(this.first) + " " + s[1:-1] + ")" | ||
else: | ||
return "(" + repr(this.first) + " . " + repr(this.rest) + ")" | ||
|
||
|
||
|
||
|
||
def foldl(f, x, ls): | ||
if ls == nil: | ||
return x | ||
else: | ||
return foldl(f, f(x, ls.first), ls.rest) | ||
|
||
|
||
|
||
|
||
def length(ls): | ||
if ls == nil: | ||
return 0 | ||
else: | ||
return 1 + length(ls.rest) | ||
|
||
|
||
|
||
|
||
def atomAssoc(u, v): | ||
return Cons(Cons(u, v), nil) | ||
|
||
|
||
|
||
|
||
def mkList(pylist): | ||
if (pylist == []): | ||
return nil | ||
else: | ||
return Cons(pylist[0], mkList(pylist[1:])) | ||
|
||
|
||
|
||
|
||
def toList(ls): | ||
ret = [] | ||
while ls <> nil: | ||
ret.append(ls.first) | ||
ls = ls.rest | ||
return ret | ||
|
||
|
||
|
||
|
||
def ext(x, v, s): | ||
return Cons(Cons(x, v), s) | ||
|
||
|
||
|
||
|
||
def append(ls1, ls2): | ||
if (ls1 == nil): | ||
return ls2 | ||
else: | ||
return append(ls1.rest, Cons(ls1.first, ls2)) | ||
|
||
|
||
|
||
|
||
def assq(x, s): | ||
while s <> nil: | ||
if x == s.first.first: | ||
return s.first | ||
else: | ||
s = s.rest | ||
return None | ||
|
||
# if (s == nil): | ||
# return None | ||
# elif (x == s.first.first): | ||
# return s.first | ||
# else: | ||
# return assq(x, s.rest) | ||
|
||
|
||
# lookup is unchanged, but it is moved in relative | ||
# position to other functions. | ||
def lookup(x, s): | ||
p = assq(x, s) | ||
if p <> None: | ||
return p.snd | ||
else: | ||
return None | ||
|
||
|
||
|
||
# cmap was renamed to maplist, but the function | ||
# has been modified significantly since renaming. | ||
# Thus we no longer consider them to be the same | ||
# function. | ||
def cmap(f, ls): | ||
if (ls == nil): | ||
return nil | ||
else: | ||
return Cons(f(ls.first), cmap(f, ls.rest)) | ||
|
||
|
||
# reverse is unchanged | ||
def reverse(ls): | ||
ret = nil | ||
while ls <> nil: | ||
ret = Cons(ls.first, ret) | ||
ls = ls.rest | ||
return ret | ||
|
||
|
||
|
||
# cfilter was renamed to filterlist, but the | ||
# function has been modified significantly since | ||
# renaming. Thus we no longer consider them to be | ||
# the same function. | ||
def cfilter(f, ls): | ||
ret = nil | ||
while ls <> nil: | ||
if f(ls.first): | ||
ret = Cons(ls.first, ret) | ||
ls = ls.rest | ||
return reverse(ret) | ||
|
||
# if (ls == nil): | ||
# return nil | ||
# elif f(ls.first): | ||
# return Cons(ls.first, cfilter(f, ls.rest)) | ||
# else: | ||
# return cfilter(f, ls.rest) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
################################################################## | ||
# Demo for an AST-based diffing tool | ||
# author: Yin Wang (yinwang0@gmail.com) | ||
################################################################## | ||
|
||
################################################################## | ||
# Features: | ||
# - Detect insertion, deletion and modification of code | ||
# - Detect refactoring (renamed or moved code) | ||
# - Assess similarity of code | ||
# - Ignore comments and whitespaces | ||
# | ||
################################################################### | ||
# Usage: | ||
# | ||
# - Mouseover any framed elements to show information | ||
# | ||
# - Click on Blue or White elements to match the other side. | ||
# Once matched, the two sides will be locked into that | ||
# position until next match. | ||
# | ||
#################################################################### | ||
# Legend of colors: | ||
# | ||
# - Red : deleted | ||
# - Green : inserted | ||
# - Blue : modified (mouse over to show percentage of change) | ||
# - White : unchanged or moved | ||
# | ||
################################################################### | ||
|
||
|
||
|
||
|
||
|
||
class PairIterator: | ||
def __init__(self, p): | ||
self.p = p | ||
def next(self): | ||
if self.p == nil: | ||
raise StopIteration | ||
ret = self.p.fst | ||
self.p = self.p.snd | ||
return ret | ||
|
||
|
||
|
||
|
||
class Nil: | ||
def __repr__(self): | ||
return "()" | ||
def __iter__(self): | ||
return PairIterator(self) | ||
|
||
nil = Nil() # singleton instance of Nil | ||
|
||
|
||
|
||
|
||
class Pair: | ||
def __init__(self, fst, snd): | ||
self.fst = fst | ||
self.snd = snd | ||
def __repr__(self): | ||
if (self.snd == nil): | ||
return "(" + repr(self.fst) + ")" | ||
elif (isinstance(self.snd, Pair)): | ||
s = repr(self.snd) | ||
return "(" + repr(self.fst) + " " + s[1:-1] + ")" | ||
else: | ||
return "(" + repr(self.fst) + " . " + repr(self.snd) + ")" | ||
def __iter__(self): | ||
return PairIterator(self) | ||
|
||
|
||
|
||
|
||
def foldl(f, x, ls): | ||
ret = x | ||
for y in ls: | ||
ret = f(ret, y) | ||
return ret | ||
|
||
|
||
|
||
|
||
def length(ls): | ||
ret = 0 | ||
for x in ls: | ||
ret = ret + 1 | ||
return ret | ||
|
||
|
||
|
||
|
||
def assoc(u, v): | ||
return Pair(Pair(u, v), nil) | ||
|
||
|
||
|
||
|
||
def slist(pylist): | ||
ret = nil | ||
for i in xrange(len(pylist)): | ||
ret = Pair(pylist[len(pylist)-i-1], ret) | ||
return ret | ||
|
||
|
||
|
||
|
||
def pylist(ls): | ||
ret = [] | ||
for x in ls: | ||
ret.append(x) | ||
return ret | ||
|
||
|
||
|
||
# maplist was renamed from cmap, but the function | ||
# has been modified significantly since renaming. | ||
# Thus we no longer consider them to be the same | ||
# function. | ||
def maplist(f, ls): | ||
ret = nil | ||
for x in ls: | ||
ret = Pair(f(x), ret) | ||
return reverse(ret) | ||
|
||
|
||
|
||
# filterlist was renamed from cfilter, but the | ||
# function has been modified significantly since | ||
# renaming. Thus we no longer consider them to be | ||
# the same function. | ||
def filterlist(f, ls): | ||
ret = nil | ||
for x in ls: | ||
if f(x): | ||
ret = Pair(x, ret) | ||
return reverse(ret) | ||
|
||
|
||
|
||
def reverse(ls): | ||
ret = nil | ||
while ls <> nil: | ||
ret = Cons(ls.first, ret) | ||
ls = ls.rest | ||
return ret | ||
|
||
# def reverse(ls): | ||
# ret = nil | ||
# for x in ls: | ||
# ret = Pair(x, ret) | ||
# return ret | ||
|
||
|
||
|
||
|
||
def append(*lists, **kw): | ||
def append1(ls1, ls2): | ||
ret = ls2 | ||
for x in ls1: | ||
ret = Pair(x, ret) | ||
return ret | ||
return foldl(append1, nil, slist(lists)) | ||
|
||
|
||
|
||
|
||
def assq(x, s): | ||
for p in s: | ||
if x == p.fst: | ||
return p | ||
return None | ||
|
||
|
||
|
||
|
||
def ziplist(ls1, ls2): | ||
ret = nil | ||
while ls1 <> nil and ls2 <> nil: | ||
ret = Pair(Pair(ls1.fst, ls2.fst), ret) | ||
ls1 = ls1.snd | ||
ls2 = ls2.snd | ||
return reverse(ret) | ||
|
||
|
||
|
||
|
||
# building association lists | ||
def ext(x, v, s): | ||
return Pair(Pair(x, v), s) | ||
|
||
|
||
|
||
|
||
def lookup(x, s): | ||
p = assq(x, s) | ||
if p <> None: | ||
return p.snd | ||
else: | ||
return None | ||
|
||
|
Oops, something went wrong.