From f654f1e7ef47c591bb5ea23f1234289f99d09d05 Mon Sep 17 00:00:00 2001 From: chessai Date: Sat, 20 Jun 2020 01:07:22 -0700 Subject: [PATCH] build with TH 2.16 --- src/Language/Haskell/Extract.hs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Language/Haskell/Extract.hs b/src/Language/Haskell/Extract.hs index 3e8958b..2edae6c 100644 --- a/src/Language/Haskell/Extract.hs +++ b/src/Language/Haskell/Extract.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + module Language.Haskell.Extract ( functionExtractor, functionExtractorMap, @@ -14,36 +16,39 @@ extractAllFunctions pattern = return $ nub $ filter (=~pattern) $ map fst $ concat $ map lex $ lines file -- | Extract the names and functions from the module where this function is called. --- +-- -- > foo = "test" -- > boo = "testing" -- > bar = $(functionExtractor "oo$") --- +-- -- will automagically extract the functions ending with "oo" such as --- +-- -- > bar = [("foo",foo), ("boo",boo)] functionExtractor :: String -> ExpQ functionExtractor pattern = do functions <- extractAllFunctions pattern +#if MIN_VERSION_template_haskell(2,16,0) + let makePair n = TupE [ Just $ LitE $ StringL n , Just $ VarE $ mkName n] +#else let makePair n = TupE [ LitE $ StringL n , VarE $ mkName n] +#endif return $ ListE $ map makePair 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. -- -- > secondTypeclassTest = -- > do let expected = ["45", "88.8", "\"hej\""] -- > actual = $(functionExtractorMap "^tc" [|\n f -> show f|] ) -- > expected @=? actual --- > +-- > -- > tcInt :: Integer -- > tcInt = 45 --- > +-- > -- > tcDouble :: Double -- > tcDouble = 88.8 --- > +-- > -- > tcString :: String -- > tcString = "hej" functionExtractorMap :: String -> ExpQ -> ExpQ