on master help sign in
Implement diffing of ASTs
41a54camrkkrp
ormolu.cabal+1
@@ -34,6 +34,7 @@ library
34 , ghc-boot-th >= 8.4.3
34 , ghc-boot-th >= 8.4.3
35 , ghc-exactprint >= 0.5.6
35 , ghc-exactprint >= 0.5.6
36 , mtl >= 2.0 && < 3.0
36 , mtl >= 2.0 && < 3.0
37+ , syb >= 0.7 && < 0.8
37 , text >= 0.2 && < 1.3
38 , text >= 0.2 && < 1.3
38 exposed-modules: Ormolu
39 exposed-modules: Ormolu
39 , Ormolu.Config
40 , Ormolu.Config
src/Ormolu/Diff.hs+18−1
@@ -1,3 +1,6 @@
1+{-# LANGUAGE DeriveDataTypeable #-}
2+{-# LANGUAGE RankNTypes #-}
3+
1-- | Diffing GHC ASTs modulo span positions.
4-- | Diffing GHC ASTs modulo span positions.
2
5
3module Ormolu.Diff
6module Ormolu.Diff
@@ -5,6 +8,7 @@ module Ormolu.Diff
5 )
8 )
6where
9where
7
10
11+import Data.Generics
8import GHC
12import GHC
9import Language.Haskell.GHC.ExactPrint.Types
13import Language.Haskell.GHC.ExactPrint.Types
10
14
@@ -15,4 +19,17 @@ diff
15 :: (Anns, ParsedSource) -- ^ First annotated AST
19 :: (Anns, ParsedSource) -- ^ First annotated AST
16 -> (Anns, ParsedSource) -- ^ Second annotated AST
20 -> (Anns, ParsedSource) -- ^ Second annotated AST
17 -> Bool
21 -> 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