[commit: haddock] master: Implement utility method for extracting variable identifiers from AST. (74de002)
git at git.haskell.org
git at git.haskell.org
Wed Jul 8 08:39:44 UTC 2015
Repository : ssh://git@git.haskell.org/haddock
On branch : master
Link : http://git.haskell.org/haddock.git/commitdiff/74de0021815f0642a89017fbb1fbdf18064cb5ea
>---------------------------------------------------------------
commit 74de0021815f0642a89017fbb1fbdf18064cb5ea
Author: Łukasz Hanuszczak <lukasz.hanuszczak at gmail.com>
Date: Sat Jun 6 19:36:53 2015 +0200
Implement utility method for extracting variable identifiers from AST.
>---------------------------------------------------------------
74de0021815f0642a89017fbb1fbdf18064cb5ea
haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs
index abd3ca2..62c0d43 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
More information about the ghc-commits
mailing list