Commit 57bca4cc authored by Steffen Michels's avatar Steffen Michels

better diff for ADTs

parent 7fcd0b86
...@@ -44,6 +44,13 @@ gDiff{|Expr|} x y = case (x,y) of ...@@ -44,6 +44,13 @@ gDiff{|Expr|} x y = case (x,y) of
(ExprBool a, ExprBool b) -> gDiff{|*|} a b (ExprBool a, ExprBool b) -> gDiff{|*|} a b
(ExprReal a, ExprReal b) -> gDiff{|*|} a b (ExprReal a, ExprReal b) -> gDiff{|*|} a b
(ExprString a, ExprString b) -> gDiff{|*|} a b (ExprString a, ExprString b) -> gDiff{|*|} a b
(ExprApp a, ExprApp b) | a.[0] == b.[0] -> [
{ status = parentStatus argDiffs
, value = toString a.[0]
, children = argDiffs
}]
where
argDiffs = flatten [gDiff{|*|} x y \\ x <-: a & y <-: b & n <- [0..] | n > 0]
(ExprTuple a, ExprTuple b) -> gDiff{|*|} a b (ExprTuple a, ExprTuple b) -> gDiff{|*|} a b
(ExprList a, ExprList b) -> gDiff{|*|} a b (ExprList a, ExprList b) -> gDiff{|*|} a b
(ExprArray a, ExprArray b) -> gDiff{|*|} a b (ExprArray a, ExprArray b) -> gDiff{|*|} a b
...@@ -67,11 +74,11 @@ gDiff{|Expr|} x y = case (x,y) of ...@@ -67,11 +74,11 @@ gDiff{|Expr|} x y = case (x,y) of
find k vs = case [e \\ ExprField f e <-: vs | f == k] of find k vs = case [e \\ ExprField f e <-: vs | f == k] of
[e:_] -> e [e:_] -> e
_ -> abort "gDiff_Expr: internal error\n" _ -> abort "gDiff_Expr: internal error\n"
parentStatus :: [Diff] -> DiffStatus
parentStatus diffs = if (all (\d -> d.status == Common) diffs) Common Changed
_ -> simpleDiff (toString x) (toString y) _ -> simpleDiff (toString x) (toString y)
parentStatus :: [Diff] -> DiffStatus
parentStatus diffs = if (all (\d -> d.status == Common) diffs) Common Changed
simpleDiff :: !String !String -> [Diff] simpleDiff :: !String !String -> [Diff]
simpleDiff left right simpleDiff left right
| left == right = [ {status=Common, value=left, children=[]} ] | left == right = [ {status=Common, value=left, children=[]} ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment