{- | Module : $Header$ Description : Generating HTML documentation Copyright : (c) 2011 - 2014, Björn Peemöller License : OtherLicense Maintainer : bjp@informatik.uni-kiel.de Stability : experimental Portability : portable This module defines a function for generating HTML documentation pages for Curry source modules. -} module Html.CurryHtml (source2html) where import Control.Monad.Writer import Control.Monad.Trans.Either import Data.Maybe (fromMaybe, isJust) import System.FilePath ((>), dropFileName, takeBaseName) import Curry.Base.Ident (QualIdent (..), unqualify) import Curry.Base.Monad import Curry.Base.Pretty (text) import Curry.Files.PathUtils (readModule, lookupCurryFile) import Curry.Syntax (Module, lexSource) import Html.SyntaxColoring import Base.Messages import CompilerOpts (Options (..)) import CurryBuilder (buildCurry) import Modules (loadAndCheckModule) import Transformations (qual) -- translate source file into HTML file with syntaxcoloring -- @param sourcefilename source2html :: Options -> FilePath -> CYIO () source2html opts f = do let baseName = takeBaseName f outDir = fromMaybe (dropFileName f) $ optHtmlDir opts outFile = outDir > baseName ++ "_curry.html" srcFile <- liftIO $ lookupCurryFile (optImportPaths opts) f program <- filename2program opts (fromMaybe f srcFile) liftIO $ writeFile outFile (program2html baseName program) -- @param importpaths -- @param filename -- @return program filename2program :: Options -> String -> CYIO [Code] filename2program opts f = do mbModule <- liftIO $ readModule f case mbModule of Nothing -> left [message $ text $ "Missing file: " ++ f] Just src -> do toks <- liftCYM $ lexSource f src typed <- fullParse opts f src return (genProgram typed toks) -- |Return the syntax tree of the source program 'src' (type 'Module'; see -- Module "CurrySyntax").after inferring the types of identifiers. -- 'fullParse' always searches for standard Curry libraries in the path -- defined in the -- environment variable "PAKCSLIBPATH". Additional search paths can -- be defined using the argument 'paths'. fullParse :: Options -> FilePath -> String -> CYIO Module fullParse opts fn _ = do buildCurry (opts { optTargetTypes = []}) fn (env, mdl) <- loadAndCheckModule opts fn return (fst $ qual opts env mdl) -- generates htmlcode with syntax highlighting -- @param modulname -- @param a program -- @return HTMLcode program2html :: String -> [Code] -> String program2html modulname codes = unlines [ "" , "", "
", "" ++ lineHtml ++ " | "
, "" ++ codeHtml ++ " | "
, "