HaTeX-meta 1.0.0 → 1.1.0
raw patch · 3 files changed
+63/−19 lines, 3 filesdep +Cabal
Dependencies added: Cabal
Files
- HaTeX-meta.cabal +3/−2
- MetaHaTeX.hs +54/−16
- ReleaseNotes +6/−1
HaTeX-meta.cabal view
@@ -1,10 +1,10 @@ Name: HaTeX-meta-Version: 1.0.0+Version: 1.1.0 Cabal-Version: >= 1.6 Build-Type: Simple License: BSD3 License-file: license-Maintainer: Daniel Díaz {danieldiaz <at> dhelta <dot> net}+Maintainer: Daniel Díaz (danieldiaz <at> dhelta <dot> net) Stability: Experimental Homepage: http://dhelta.net/hprojects/HaTeX-meta Bug-reports: danieldiaz <at> dhelta <dot> net@@ -27,4 +27,5 @@ , containers == 0.4.* , directory == 1.* , filepath == 1.*+ , Cabal == 1.10.* Main-is: MetaHaTeX.hs
MetaHaTeX.hs view
@@ -1,6 +1,7 @@ import Prelude hiding (lookup) import Language.Haskell.Exts hiding (ModuleName)+import qualified Language.Haskell.Exts as LH import Documentation.Haddock hiding (Decl) import Control.Monad.State import Data.Maybe@@ -14,6 +15,15 @@ import System.FilePath (dropFileName) import System.Directory (createDirectoryIfMissing) import Data.Char (isAlpha)+import System.IO (hFlush,stdout)+import Control.Monad (filterM)+-- Cabal+import Distribution.PackageDescription+ (exposedModules,condTreeData,condLibrary)+import Distribution.PackageDescription.Parse+ (readPackageDescription)+import Distribution.Verbosity (silent)+import Distribution.ModuleName (components) -- | Module names are written with 'String's. type ModuleName = String@@ -24,22 +34,45 @@ -> ModuleName -- New module name monadMName mn = mn ++ ".Monad" +-- | All exposed modules of HaTeX.+allExposed :: IO [ModuleName]+allExposed =+ fmap+ (fmap (intercalate "." . components)+ . exposedModules . condTreeData . fromJust . condLibrary)+ $ readPackageDescription silent "HaTeX.cabal"+ -- | The list of modules to be transformed by HaTeX-meta.-moduleList :: [ModuleName]-moduleList = [- "Text.LaTeX.Base.Commands"- , "Text.LaTeX.Packages.AMSFonts"- , "Text.LaTeX.Packages.AMSMath"- , "Text.LaTeX.Packages.Beamer"- , "Text.LaTeX.Packages.Hyperref"- , "Text.LaTeX.Packages.Inputenc"- , "Text.LaTeX.Packages.Color"- ]+moduleList :: IO [ModuleName]+moduleList =+ allExposed >>=+ filterM+ (fmap (hatexPragma . fromParseResult) . parseFileS . mNameToFilePath) +parseFileS :: FilePath -> IO (ParseResult Module)+parseFileS fp = parseFile fp `catch` \e -> do+ let name = filePathToMName fp+ putStrLn $ "HaTeX-meta: The module " ++ name ++ " does not exist."+ return $ ParseOk $ Module loc0 (LH.ModuleName name) [] Nothing Nothing [] []++-- | Check if a module has the HaTeX /MakeMonadic/ option:+--+-- > {-# OPTIONS_HATEX MakeMonadic #-}+hatexPragma :: Module -> Bool+hatexPragma (Module _ _ pragmas _ _ _ _) = any isMonadicPragma pragmas++isMonadicPragma :: ModulePragma -> Bool+isMonadicPragma (OptionsPragma _ (Just (UnknownTool "HATEX")) str) =+ takeWhile isAlpha str == "MakeMonadic"+isMonadicPragma _ = False+ -- | Get the 'FilePath' of a 'ModuleName'. mNameToFilePath :: ModuleName -> FilePath mNameToFilePath = (++ ".hs") . fmap (\c -> if c == '.' then '/' else c) +filePathToMName :: FilePath -> ModuleName+filePathToMName = fmap (\c -> if c == '/' then '.' else c) . reverse . drop 3 . reverse+ nameString :: Name -> String nameString = prettyPrint @@ -120,7 +153,8 @@ -- Final result return $ HSI { hsModuleName = mn- , hsPragma = unlines $ fmap prettyPrint pragmas+ , hsPragma = unlines $ fmap prettyPrint+ $ filter (not . isMonadicPragma) $ pragmas , hsModuleInfo = ifaceDoc i , hsExportList = expList , hsTypeNames = catMaybes $ fmap getTypeName decls@@ -241,7 +275,8 @@ , unwords [n , "::" , prettyPrint $ TyForall Nothing [ClassA (UnQual $ Ident "Monad")- [TyVar $ Ident "m"]]+ [TyVar $ Ident "m"]+ ] $ latexType t] , prettyPrint $ FunBind [Match loc0@@ -291,7 +326,6 @@ , hatexmetawarn $ hsModuleName hsi ] , hsExportList hsi ++ "\n" , importString hsi- -- , unlines2 $ fmap typeSynonym $ hsTypeNames hsi , unlines $ fmap monadicFunction $ hsFunInfo hsi ] @@ -299,12 +333,16 @@ main :: IO () main = do- is <- createInterfaces [] moduleList- mapM_ (\m -> do let fp = mNameToFilePath m+ mlist <- moduleList+ is <- createInterfaces [] mlist+ mapM_ (\m -> do putStr $ "HaTeX-meta: Processing " ++ m ++ "... "+ hFlush stdout+ let fp = mNameToFilePath m fp' = mNameToFilePath $ monadMName m i = fromJust $ find (\x -> (GHC.moduleNameString $ GHC.moduleName $ ifaceMod x) == m) is createDirectoryIfMissing True $ dropFileName fp' getHSInfo m i >>= writeFile fp' . buildMonadModule- ) moduleList+ putStrLn "Done."+ ) mlist
ReleaseNotes view
@@ -1,5 +1,10 @@ HaTeX-meta Release Notes --- From version 1.0.0 +-- From version 1.0.0++>>> 1.1.0++* Added the HaTeX pragma feature. More details in:+http://deltadiaz.blogspot.com/2011/11/hatex-pragma.html >>> 1.0.0