packages feed

language-haskell-extract 0.2.3 → 0.2.4

raw patch · 2 files changed

+14/−62 lines, 2 filesdep −haskell-src-extsdep ~basedep ~template-haskell

Dependencies removed: haskell-src-exts

Dependency ranges changed: base, template-haskell

Files

language-haskell-extract.cabal view
@@ -1,5 +1,5 @@ name: language-haskell-extract-version: 0.2.3+version: 0.2.4 cabal-version: >=1.6 build-type: Simple license: BSD3@@ -48,12 +48,13 @@    > tcString = "hej" category: Template Haskell author: Oscar Finnsson & Emil Nordling- + library+  ghc-options: -Wall   hs-source-dirs: src   exposed-modules: Language.Haskell.Extract-  build-depends: base >= 4 && < 5, regex-posix, haskell-src-exts >= 1.8.0, template-haskell+  build-depends: base >= 4 && < 5, regex-posix, template-haskell  source-repository head   type:     git-  location: https://github.com/finnsson/language-haskell-extract/+  location: http://github.com/finnsson/template-helper
src/Language/Haskell/Extract.hs view
@@ -4,42 +4,14 @@   locationModule ) where import Language.Haskell.TH-import Language.Haskell.Exts.Parser-import Language.Haskell.Exts (parseFileContentsWithMode)-import Language.Haskell.Exts.Syntax import Text.Regex.Posix-import Data.Maybe import Data.List-import Language.Haskell.Exts.Extension -extractAllFunctions :: String -> String-> [String]-extractAllFunctions pattern file  = ---  allMatchingFunctions pattern . parsedModule-  nub $ filter (\f->f=~pattern::Bool) $ map (fst . head . lex) $ lines file---- nub $ filter ("prop_" `isPrefixOf`) $--- map (fst . head . lex) $ lines ct---parsedModule moduleCode = -  let pMod = parseFileContentsWithMode (defaultParseMode { extensions = knownExtensions } ) moduleCode-      moduleOrDefault (ParseFailed _ _) = Module (SrcLoc "unknown" 1 1) (ModuleName "unknown") [] Nothing Nothing [] []-      moduleOrDefault (ParseOk m) = m-  in moduleOrDefault pMod --allFunctions =  onlyJust extractNameOfFunctionFromDecl . hsModuleDecls -allMatchingFunctions pattern = filter (\f->f=~pattern::Bool) . allFunctions ----extractNameOfFunctionFromDecl :: Decl -> Maybe String-extractNameOfFunctionFromDecl (PatBind _ (PVar (Ident n)) _ _ _ ) = Just n-extractNameOfFunctionFromDecl (FunBind ms) = Just $ head $ [n | (Language.Haskell.Exts.Syntax.Match _ (Ident n) _ _ _ _)  <- ms]-extractNameOfFunctionFromDecl _ = Nothing--onlyJust f = map fromJust . filter isJust . map f--hsModuleDecls (Module _ _ _ _ _ _ d) = d+extractAllFunctions :: String -> Q [String]+extractAllFunctions pattern =+  do loc <- location+     file <- runIO $ readFile $ loc_filename loc+     return $ nub $ filter (=~pattern) $ map fst $ concat $ map lex $ lines file  -- | Extract the names and functions from the module where this function is called. -- @@ -52,20 +24,11 @@ -- > bar = [("foo",foo), ("boo",boo)] functionExtractor :: String -> ExpQ functionExtractor pattern =-  do loc <- location-     moduleCode <- runIO $ readFile $ loc_filename loc-     let functions = extractAllFunctions pattern moduleCode-         makePair n = TupE [ LitE $ StringL n , VarE $ mkName n]+  do functions <- extractAllFunctions pattern+     let makePair n = TupE [ LitE $ StringL n , VarE $ mkName n]      return $ ListE $ map makePair functions  --- functionExtractor' :: String -> Q [String]--- functionExtractor' pattern =---   do loc <- location---      moduleCode <- runIO $ readFile $ loc_filename loc---      let functions = extractAllFunctions pattern moduleCode---      return functions- -- | Extract the names and functions from the module and apply a function to every pair. --  -- Is very useful if the common denominator of the functions is just a type class.@@ -85,23 +48,11 @@ -- > tcString = "hej" functionExtractorMap :: String -> ExpQ -> ExpQ functionExtractorMap pattern funcName =-  do loc <- location-     moduleCode <- runIO $ readFile $ loc_filename loc-     let functions :: [String]-         functions = extractAllFunctions pattern moduleCode+  do functions <- extractAllFunctions pattern      fn <- funcName      let makePair n = AppE (AppE (fn) (LitE $ StringL n)) (VarE $ mkName n)-     return $ ListE $ map makePair functions +     return $ ListE $ map makePair functions --- functionExtractorExpMap :: String -> (Exp -> ExpQ) -> ExpQ--- functionExtractorExpMap pattern func =---   do loc <- location---      moduleCode <- runIO $ readFile $ loc_filename loc---      let functions :: [String]---          functions = extractAllFunctions pattern moduleCode---      fn <- funcName---      let makePair n = AppE (AppE (fn) (LitE $ StringL n)) (VarE $ mkName n)---      return $ ListE $ map makePair functions     -- | Extract the name of the current module. locationModule :: ExpQ