@@ -1,3 +1,6 @@
1+{-# LANGUAGE DeriveDataTypeable #-}
2+{-# LANGUAGE RankNTypes #-}
3+
14-- | Diffing GHC ASTs modulo span positions.
25
36module Ormolu.Diff
@@ -5,6 +8,7 @@ module Ormolu.Diff
58 )
69where
710
11+import Data.Generics
812import GHC
913import Language.Haskell.GHC.ExactPrint.Types
1014
@@ -15,4 +19,17 @@ diff
1519 :: (Anns, ParsedSource) -- ^ First annotated AST
1620 -> (Anns, ParsedSource) -- ^ Second annotated AST
1721 -> Bool
18−diff _ _ = False -- TODO
22+diff (_, ps0) (_, ps1) =
23+ not (matchParsedSources ps0 ps1)
24+
25+-- | Compare two 'ParsedSource' values disregarding differences in
26+-- 'SrcSpan's.
27+
28+matchParsedSources :: ParsedSource -> ParsedSource -> Bool
29+matchParsedSources x0 y0 = geq' x0 y0
30+ where
31+ geq' :: GenericQ (GenericQ Bool)
32+ geq' x y = (toConstr x == toConstr y)
33+ && and (gzipWithQ (geq' `extQ` srcSpanEq) x y)
34+ srcSpanEq :: SrcSpan -> GenericQ Bool
35+ srcSpanEq _ _ = True