summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2012-09-28 00:48:36 +1000
committerJed Barber <jjbarber@y7mail.com>2012-09-28 00:48:36 +1000
commitec2487e62240dcc3b98a9a3f7c017574af34be2a (patch)
tree545dc6e1585ab02c8ad1d7d492ec452ae2f8e6ac
parent0130c834481c99f9f9f4da527acb4d712aa1f664 (diff)
Now shows what the differences between article files are
-rw-r--r--Compare.hs39
1 files changed, 32 insertions, 7 deletions
diff --git a/Compare.hs b/Compare.hs
index 4d9ab6d..b60250f 100644
--- a/Compare.hs
+++ b/Compare.hs
@@ -2,17 +2,42 @@ import System.Environment( getArgs )
import Text.Printf
import Library.Parse
import Library.Semantic
-import Library.Stack
-
+import qualified Library.Stack as Stack
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+import Data.Maybe
main = do
args <- getArgs
listA <- getLines (args!!0)
listB <- getLines (args!!1)
- let resultA = eval (map (stripReturn) listA)
- resultB = eval (map (stripReturn) listB)
- output = if (resultA == resultB)
- then "Articles identical\n"
- else "Differences detected\n"
+
+ let result = do resultA <- eval (map stripReturn listA)
+ resultB <- eval (map stripReturn listB)
+ let (sA,dA,aA,tA) = resultA
+ (sB,dB,aB,tB) = resultB
+
+ sA_diff = Stack.diff sA sB
+ sB_diff = Stack.diff sB sA
+
+ dA_diff = dA Map.\\ dB
+ dB_diff = dB Map.\\ dA
+
+ aA_diff = aA Set.\\ aB
+ aB_diff = aB Set.\\ aA
+
+ tA_diff = tA Set.\\ tB
+ tB_diff = tB Set.\\ tA
+ return (Just (sA_diff,dA_diff,aA_diff,tA_diff),
+ Just (sB_diff,dB_diff,aB_diff,tB_diff))
+
+ output = if (isNothing result)
+ then "Error in article files\n"
+ else let (diff_A, diff_B) = fromJust result
+ in if (diff_A == diff_B)
+ then "Articles identical\n"
+ else (args!!0) ++ " has:\n" ++ (fromJust . machineToString $ diff_A) ++ "\n" ++
+ (args!!1) ++ " has:\n" ++ (fromJust . machineToString $ diff_B) ++ "\n"
+
printf output