From e9d61b79faf40200d8f9806d83a05ece272cd7d3 Mon Sep 17 00:00:00 2001 From: Ɓukasz Hanuszczak Date: Fri, 10 Jul 2015 11:42:18 +0200 Subject: Move SYB utilities to standalone module. --- .../src/Haddock/Backends/Hyperlinker/Ast.hs | 15 +------------ haddock-api/src/Haddock/Syb.hs | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 haddock-api/src/Haddock/Syb.hs (limited to 'haddock-api/src') diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs index 71b73663..5eca973e 100644 --- a/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs +++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs @@ -6,6 +6,7 @@ module Haddock.Backends.Hyperlinker.Ast (enrich) where +import Haddock.Syb import Haddock.Backends.Hyperlinker.Types import qualified GHC @@ -179,17 +180,3 @@ matches tspan (GHC.RealSrcSpan aspan) saspan = (GHC.srcSpanStartLine aspan, GHC.srcSpanStartCol aspan) easpan = (GHC.srcSpanEndLine aspan, GHC.srcSpanEndCol aspan) matches _ _ = False - --- | Perform a query on each level of a tree. --- --- This is stolen directly from SYB package and copied here to not introduce --- additional dependencies. -everything :: (r -> r -> r) -> (forall a. Data a => a -> r) - -> (forall a. Data a => a -> r) -everything k f x = foldl k (f x) (gmapQ (everything k f) x) - --- | Combine two queries into one using alternative combinator. -combine :: Alternative f => (forall a. Data a => a -> f r) - -> (forall a. Data a => a -> f r) - -> (forall a. Data a => a -> f r) -combine f g x = f x <|> g x diff --git a/haddock-api/src/Haddock/Syb.hs b/haddock-api/src/Haddock/Syb.hs new file mode 100644 index 00000000..dd7ffc1b --- /dev/null +++ b/haddock-api/src/Haddock/Syb.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE Rank2Types #-} + + +module Haddock.Syb + ( everything + , combine + ) where + + +import Data.Data +import Control.Applicative + + +-- | Perform a query on each level of a tree. +-- +-- This is stolen directly from SYB package and copied here to not introduce +-- additional dependencies. +everything :: (r -> r -> r) -> (forall a. Data a => a -> r) + -> (forall a. Data a => a -> r) +everything k f x = foldl k (f x) (gmapQ (everything k f) x) + +-- | Combine two queries into one using alternative combinator. +combine :: Alternative f => (forall a. Data a => a -> f r) + -> (forall a. Data a => a -> f r) + -> (forall a. Data a => a -> f r) +combine f g x = f x <|> g x -- cgit v1.2.3