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

Compiler option handling refactored

parent 46b35559
......@@ -12,9 +12,10 @@ Description: The Curry Frontend consists of the executable program "cymake".
Category: Language
License: OtherLicense
License-File: LICENSE
Author: Wolfgang Lux, Martin Engelke, Bernd Brassel, Holger Siegel
Maintainer: Holger Siegel
Bug-Reports: mailto:hsi@informatik.uni-kiel.de
Author: Wolfgang Lux, Martin Engelke, Bernd Brassel, Holger Siegel,
Bjoern Peemoeller
Maintainer: Bjoern Peemoeller
Bug-Reports: mailto:bjp@informatik.uni-kiel.de
Homepage: http://curry-language.org
Build-Type: Simple
Stability: experimental
......
......@@ -6,13 +6,14 @@
May 2011 , refinements by Björn Peemöller (bjp@informatik.uni-kiel.de)
-}
module CurryCompilerOpts
(Options (..), Dump (..), parseOpts, printUsage, printVersion, defaultOptions) where
(Options (..), Dump (..), defaultOptions, compilerOpts, usage) where
import Data.List (nub)
import Data.Maybe (isJust)
import System.Console.GetOpt
import System.Environment (getArgs, getProgName)
import Curry.Files.Filenames (currySubdir)
import Files.CymakePath (cymakeGreeting)
-- |Data type for recording compiler options
data Options = Options
......@@ -167,12 +168,22 @@ parseOpts :: [String] -> (Options, [String], [String])
parseOpts args = (foldl (flip ($)) defaultOptions opts, files, errs) where
(opts, files, errs) = getOpt Permute options args
-- |Check options and files and return a list of error messages
checkOpts :: Options -> [String] -> [String]
checkOpts opts files
| isJust (output opts) && length files > 1
= ["cannot specify -o with multiple targets"]
| otherwise
= []
-- |Print the usage information of the command line tool.
printUsage :: String -> IO ()
printUsage prog = putStrLn $ usageInfo header options
usage :: String -> String
usage prog = usageInfo header options
where header = "usage: " ++ prog ++ " [OPTION] ... MODULE ..."
-- |Print the program greeting
printVersion :: IO ()
printVersion = putStrLn cymakeGreeting
compilerOpts :: IO (String, Options, [String], [String])
compilerOpts = do
args <- getArgs
prog <- getProgName
let (opts, files, errs) = parseOpts args
return (prog, opts, files, errs ++ checkOpts opts files)
......@@ -25,7 +25,7 @@ import Base (ModuleEnv, TCEnv, ValueEnv, TypeInfo (..), ValueInfo (..)
, lookupValue, qualLookupTC, qualLookupValue, ArityEnv, ArityInfo (..)
, lookupArity, qualLookupArity)
import CurryCompilerOpts
import CurryCompilerOpts (Options (..))
import qualified CurryToIL as IL
import Env.TopEnv (topEnvMap)
import Env.CurryEnv (CurryEnv)
......
......@@ -8,49 +8,43 @@
-}
module Main (main) where
import Data.Maybe (isJust)
import System.Environment (getArgs, getProgName)
import CurryBuilder (buildCurry)
import CurryCompilerOpts (Options (..), parseOpts, printUsage, printVersion)
import CurryCompilerOpts (Options (..), compilerOpts, usage)
import Files.CymakePath (cymakeGreeting)
import Html.CurryHtml (source2html)
import Messages (info, putErrsLn, abortWith)
import Messages (putErrsLn, abortWith)
-- |The command line tool cymake
main :: IO ()
main = do
prog <- getProgName
args <- getArgs
cymake prog (parseOpts args)
main = compilerOpts >>= cymake
-- |Check the command line arguments and invoke the curry builder
cymake :: String -> (Options, [String], [String]) -> IO ()
cymake prog (opts, files, errs)
cymake :: (String, Options, [String], [String]) -> IO ()
cymake (prog, opts, files, errs)
| help opts = printUsage prog
| version opts = printVersion
| null files = printUsage prog
| not (null errs') = badUsage prog errs'
| not (null errs) = badUsage prog errs
| html opts = mapM_ (source2html opts) files
| otherwise = info opts cymakeGreeting
>> mapM_ (buildCurry opts') files
| otherwise = mapM_ (buildCurry opts') files
where
opts' = if or [ flat opts, flatXml opts, abstract opts
, untypedAbstract opts, parseOnly opts]
then opts
else opts { flat = True }
errs' = errs ++ check opts' files
-- |Print errors
-- ---------------------------------------------------------------------------
-- |Print the program greeting
printVersion :: IO ()
printVersion = putStrLn cymakeGreeting
-- |Print the usage information of the command line tool.
printUsage :: String -> IO ()
printUsage prog = putStrLn $ usage prog
-- |Print errors and abort execution
badUsage :: String -> [String] -> IO ()
badUsage prog errs = do
putErrsLn $ map (\ err -> prog ++ ": " ++ err) errs
abortWith ["Try '" ++ prog ++ " --help' for more information"]
-- |Check options and files and return a list of error messages
check :: Options -> [String] -> [String]
check opts files
| isJust (output opts) && length files > 1
= ["cannot specify -o with multiple targets"]
| otherwise
= []
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