1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE RankNTypes #-}
3{-# LANGUAGE RecordWildCards #-}
5-- | Diffing GHC ASTs modulo span positions.
13import Data.Maybe (mapMaybe)
15import Language.Haskell.GHC.ExactPrint.Types
17import qualified Data.Map.Strict as M
19-- | Return 'False' of two annotated ASTs are the same modulo span
23 :: (Anns, ParsedSource) -- ^ First annotated AST
24 -> (Anns, ParsedSource) -- ^ Second annotated AST
26diff (anns0, ps0) (anns1, ps1) =
27 not (matchIgnoringSrcSpans (simplifyAnns anns0) (simplifyAnns anns1))
28 || not (matchIgnoringSrcSpans ps0 ps1)
30-- | Compare two 'ParsedSource' values disregarding differences in
33matchIgnoringSrcSpans :: Data a => a -> a -> Bool
34matchIgnoringSrcSpans x0 y0 = geq' x0 y0
36 geq' :: GenericQ (GenericQ Bool)
37 geq' x y = (toConstr x == toConstr y)
38 && and (gzipWithQ (geq' `extQ` srcSpanEq) x y)
39 srcSpanEq :: SrcSpan -> GenericQ Bool
42-- | Simplified collection of 'Comment's.
44data Comments = Comments [Comment] [Comment] [Comment]
45 deriving (Show, Typeable, Data)
47-- | Simplify a collection of annotations.
49simplifyAnns :: Anns -> [Comments]
50simplifyAnns = fmap simplifyAnn . M.elems
52-- | Simplify single annotation.
54simplifyAnn :: Annotation -> Comments
55simplifyAnn Ann {..} = Comments
56 (f . fst <$> annPriorComments)
57 (f . fst <$> annFollowingComments)
58 (mapMaybe (fmap f . annComment) (fst <$> annsDP))
61 Comment (unlines $ normalizeComment str) i o
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list