Commit e9d5da2e authored by Camil Staps's avatar Camil Staps 🍃

Merge branch 'improveExprDiff' into 'master'

Improve diff for Expr

See merge request !6
parents 112c0528 81befe06
Pipeline #12621 passed with stage
in 40 seconds
......@@ -44,9 +44,20 @@ gDiff{|Expr|} x y = case (x,y) of
(ExprBool a, ExprBool b) -> gDiff{|*|} a b
(ExprReal a, ExprReal b) -> gDiff{|*|} a b
(ExprString a, ExprString b) -> gDiff{|*|} a b
(ExprTuple a, ExprTuple 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) -> [ {diff & value="_Tuple"}
\\ diff <- gDiff{|*->*|} gDiff{|*|} [x \\ x <-: a] [y \\ y <-: b]
]
(ExprList a, ExprList b) -> gDiff{|*|} a b
(ExprArray a, ExprArray b) -> gDiff{|*|} a b
(ExprArray a, ExprArray b) -> [ {diff & value="_Array"}
\\ diff <- gDiff{|*->*|} gDiff{|*|} [x \\ x <- a] [y \\ y <- b]
]
(ExprRecord r1 xs, ExprRecord r2 ys) | r1 == r2 -> [
{ status = parentStatus field_diffs
, value = fromMaybe "<unnamed record>" r1
......@@ -67,14 +78,15 @@ gDiff{|Expr|} x y = case (x,y) of
find k vs = case [e \\ ExprField f e <-: vs | f == k] of
[e:_] -> e
_ -> 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)
parentStatus :: [Diff] -> DiffStatus
parentStatus diffs = if (all (\d -> d.status == Common) diffs) Common Changed
simpleDiff :: !String !String -> [Diff]
simpleDiff left right =
[ {status=OnlyLeft, value=left, children=[]}
simpleDiff left right
| left == right = [ {status=Common, value=left, children=[]} ]
| otherwise = [ {status=OnlyLeft, value=left, children=[]}
, {status=OnlyRight, value=right, 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