Permalink
Browse files

Added CPP processing when there is a CPP language pragma.

  • Loading branch information...
luqui committed Jan 31, 2011
1 parent 3ab9e90 commit 061810d390cb04e782ffc2fba09457507e3fcb17
Showing with 13 additions and 2 deletions.
  1. +11 −1 Main.hs
  2. +2 −1 hothasktags.cabal
View
12 Main.hs
@@ -6,6 +6,7 @@ import qualified Language.Haskell.Exts.Annotated as L
import System.Environment (getArgs)
import System.IO (hPutStrLn, stderr)
import qualified Data.Map as Map
+import qualified Language.Preprocessor.Cpphs as CPP
import Control.Monad (forM, when)
import Data.List (sort)
import Data.Maybe (fromMaybe)
@@ -157,10 +158,19 @@ makeTag refFile (name, Defn file line) = name ++ "\t" ++ file ++ "\t" ++ show li
makeTags :: FilePath -> Map.Map String Defn -> [String]
makeTags refFile = map (makeTag refFile) . Map.assocs
+haskellSource :: FilePath -> IO String
+haskellSource file = do
+ contents <- readFile file
+ let needsCpp = maybe False (L.CPP `elem`) (L.readExtensions contents)
+ if needsCpp
+ then CPP.runCpphs CPP.defaultCpphsOptions file contents
+ else return contents
+
+
makeDatabase :: [FilePath] -> IO Database
makeDatabase files = do
fmap (Map.fromList . concat) . forM files $ \file -> do
- result <- L.parseFileWithMode (mode file) file
+ result <- L.parseFileContentsWithMode (mode file) `fmap` haskellSource file
case result of
L.ParseOk mod@(L.Module _ (Just (L.ModuleHead _ (L.ModuleName _ name) _ _)) _ _ _) -> do
return [(name, mod)]
View
@@ -30,6 +30,7 @@ executable hothasktags
build-depends:
base == 4.*,
containers,
- haskell-src-exts >= 1.8 && < 1.10
+ haskell-src-exts >= 1.8 && < 1.11,
+ cpphs == 1.11.*
main-is: Main.hs
ghc-options: -W

0 comments on commit 061810d

Please sign in to comment.