From 74de0021815f0642a89017fbb1fbdf18064cb5ea Mon Sep 17 00:00:00 2001 From: Ɓukasz Hanuszczak Date: Sat, 6 Jun 2015 19:36:53 +0200 Subject: Implement utility method for extracting variable identifiers from AST. --- haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'haddock-api/src/Haddock') diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs index abd3ca2b..62c0d439 100644 --- a/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs +++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs @@ -1,6 +1,10 @@ +{-# LANGUAGE RankNTypes #-} + module Haddock.Backends.Hyperlinker.Ast where import qualified GHC +import Data.Data +import Control.Applicative import Haddock.Backends.Hyperlinker.Parser @@ -18,3 +22,15 @@ enrich src = lookupName :: GHC.RenamedSource -> Span -> Maybe GHC.Name lookupName = undefined + +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) + +variables :: GHC.RenamedSource -> [(GHC.SrcSpan, GHC.Name)] +variables = + everything (<|>) var + where + var term = case cast term of + (Just (GHC.L sspan (GHC.HsVar sid))) -> pure (sspan, sid) + _ -> empty -- cgit v1.2.3