Commit 94440029 authored by Björn Peemöller 's avatar Björn Peemöller
Browse files

Improved internal structure for HTML generation

parent 6387b29b
......@@ -13,7 +13,7 @@
This module contains functions to generate Curry representations for a
Curry source file including all imported modules.
-}
module CurryBuilder (buildCurry, smake) where
module CurryBuilder (buildCurry) where
import Control.Monad (liftM)
import Data.Maybe (catMaybes, mapMaybe)
......
{- |
Module : $Header$
Description : API to access cymake as a library
Copyright : (c) 2005, Martin Engelke (men@informatik.uni-kiel.de)
2011, Björn Peemöller (bjp@informatik.uni-kiel.de)
Copyright : (c) 2005 Martin Engelke
2011 - 2014 Björn Peemöller
License : OtherLicense
Maintainer : bjp@informatik.uni-kiel.de
......@@ -16,19 +16,14 @@ module Frontend (parse, fullParse) where
import Control.Monad.Writer
import Control.Monad.Trans.Either
import Data.Maybe (mapMaybe)
import qualified Data.Map as Map (empty)
import Curry.Base.Message
import Curry.Files.Filenames
import Curry.Files.PathUtils
import Curry.Syntax (Module (..), parseModule)
import Curry.Syntax (Module (..), parseModule)
import CompilerOpts (Options (..), defaultOptions)
import CurryBuilder (smake)
import CurryDeps (Source (..), flattenDeps, moduleDeps)
import Modules (checkModule, checkModuleHeader, compileModule, loadModule)
import CompilerOpts (Options (..), defaultOptions)
import CurryBuilder (buildCurry)
import Modules (loadAndCheckModule, checkModuleHeader)
{- |Return the result of a syntactical analysis of the source program 'src'.
The result is the syntax tree of the program (type 'Module'; see Module
......@@ -51,43 +46,21 @@ parse fn src = parseModule fn src >>= genCurrySyntax
be defined using the argument 'paths'.
-}
fullParse :: Options -> FilePath -> String -> MessageIO Module
fullParse opts fn src = genFullCurrySyntax opts fn $ parse fn src
genFullCurrySyntax :: Options -> FilePath -> MessageM Module -> MessageIO Module
genFullCurrySyntax opts fn m = case runMsg m of
Left err -> failWith $ show err
Right (mod1, _) -> do
errs <- liftIO $ makeInterfaces opts fn mod1
fullParse opts fn _ = do
errs <- liftIO $ makeInterfaces opts fn
if null errs
then do
checked <- liftIO $ runEitherT $ loadModule opts fn >>= checkModule opts
checked <- liftIO $ runEitherT $ loadAndCheckModule opts fn
case checked of
Left errs' -> failWith $ show $ head errs'
Right (_, mod') -> return mod'
else failWith $ show $ head errs
-- TODO: Resembles CurryBuilder
-- Generates interface files for importes modules, if they don't exist or
-- if they are not up-to-date.
makeInterfaces :: Options -> FilePath -> Module -> IO [Message]
makeInterfaces opts fn mdl = do
res <- runEitherT $ do
(deps1, errs) <- fmap flattenDeps $ moduleDeps opts Map.empty fn mdl
when (null errs) $ mapM_ (compile deps1 . snd) deps1
return errs
makeInterfaces :: Options -> FilePath -> IO [Message]
makeInterfaces opts fn = do
res <- runEitherT $ buildCurry opts fn
case res of
Left errs -> return errs
Right errs -> return errs
where
compile deps' (Source file' mods) = smake
[flatName file', flatIntName file']
(file':mapMaybe (flatInterface deps') mods)
(compileModule opts file')
(return ())
compile _ _ = return ()
flatInterface deps' mod1 = case lookup mod1 deps' of
Just (Source f _) -> Just $ flatIntName $ dropExtension f
Just (Interface f) -> Just $ flatIntName $ dropExtension f
_ -> Nothing
Right _ -> return []
......@@ -19,8 +19,8 @@ import Data.Maybe (fromMaybe, isJust)
import Curry.Base.Ident (QualIdent (..), unqualify)
import Curry.Base.Message (fromIO)
import Curry.Base.Pretty (text)
import Curry.Files.PathUtils
(readModule, lookupCurryFile, dropExtension, takeFileName)
import Curry.Files.Filenames (dropExtension, takeFileName)
import Curry.Files.PathUtils (readModule, lookupCurryFile)
import Curry.Syntax (lexSource)
import Html.SyntaxColoring
......
......@@ -4,7 +4,7 @@
Copyright : (c) 1999 - 2004 Wolfgang Lux
2005 Martin Engelke
2007 Sebastian Fischer
2011 - 2013 Björn Peemöller
2011 - 2014 Björn Peemöller
License : OtherLicense
Maintainer : bjp@informatik.uni-kiel.de
......@@ -15,7 +15,7 @@
-}
module Modules
( compileModule, loadModule, checkModuleHeader, checkModule, writeOutput
( compileModule, loadAndCheckModule, checkModuleHeader
) where
import qualified Control.Exception as C (catch, IOException)
......@@ -75,12 +75,16 @@ import Transformations
-- The compiler automatically loads the prelude when compiling any
-- module, except for the prelude itself, by adding an appropriate import
-- declaration to the module.
compileModule :: Options -> FilePath -> CYIO ()
compileModule opts fn = do
(env, mdl) <- loadAndCheckModule opts fn
liftIO $ writeOutput opts fn (env, mdl)
loadAndCheckModule :: Options -> FilePath -> CYIO (CompilerEnv, CS.Module)
loadAndCheckModule opts fn = do
(env, mdl) <- loadModule opts fn >>= checkModule opts
warn (optWarnOpts opts) $ warnCheck opts env mdl
liftIO $ writeOutput opts fn (env, mdl)
return (env, mdl)
-- ---------------------------------------------------------------------------
-- Loading a module
......
......@@ -2,7 +2,7 @@
Module : $Header$
Description : Main module
Copyright : (c) 2005 Martin Engelke
2011 - 2013 Björn Peemöller
2011 - 2014 Björn Peemöller
License : OtherLicense
Maintainer : bjp@informatik.uni-kiel.de
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment