{-|
Module      : Idris.Options
Description : Compiler options for Idris.

License     : BSD3
Maintainer  : The Idris Community.
-}
{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveGeneric, PatternGuards #-}

module Idris.Options (Codegen(..), ConsoleWidth(..), HowMuchDocs(..), IRFormat(..),
                      LanguageExt(..), LogCat(..), Opt(..), Optimisation(..),
                      OutputFmt(..), REPLPort(..), codegenCats, elabCats, getBC,
                      getClient, getCodegen, getCodegenArgs, getColour, getConsoleWidth,
                      getEvalExpr, getExecScript, getFile, getIBCSubDir, getImportDir,
                      getLanguageExt, getOptLevel, getOptimisation, getOutput,
                      getOutputTy, getPkg, getPkgCheck, getPkgClean, getPkgDir,
                      getPkgIndex, getPkgMkDoc, getPkgREPL, getPkgTest, getPort,
                      getSourceDir, loggingCatsStr, opt, parserCats, strLogCat) where

import Data.Maybe
import GHC.Generics (Generic)
import IRTS.CodegenCommon (OutputType)
import Network.Socket (PortNumber)

data Opt = Filename String
         | Quiet
         | NoBanner
         | ColourREPL Bool
         | Idemode
         | IdemodeSocket
         | IndentWith Int
         | IndentClause Int
         | ShowAll
         | ShowLibs
         | ShowLibDir
         | ShowDocDir
         | ShowIncs
         | ShowPkgs
         | ShowLoggingCats
         | NoBasePkgs
         | NoPrelude
         | NoBuiltins -- only for the really primitive stuff!
         | NoREPL
         | OLogging Int
         | OLogCats [LogCat]
         | Output String
         | Interface
         | TypeCase
         | TypeInType
         | DefaultTotal
         | DefaultPartial
         | WarnPartial
         | WarnReach
         | AuditIPkg
         | EvalTypes
         | NoCoverage
         | ErrContext
         | ShowImpl
         | Verbose Int
         | Port REPLPort -- ^ REPL TCP port
         | IBCSubDir String
         | ImportDir String
         | SourceDir String
         | PkgBuild String
         | PkgInstall String
         | PkgClean String
         | PkgCheck String
         | PkgREPL String
         | PkgDocBuild String -- IdrisDoc
         | PkgDocInstall String
         | PkgTest String
         | PkgIndex FilePath
         | WarnOnly
         | Pkg String
         | BCAsm String
         | DumpDefun String
         | DumpCases String
         | UseCodegen Codegen
         | CodegenArgs String
         | OutputTy OutputType
         | Extension LanguageExt
         | InterpretScript String
         | EvalExpr String
         | TargetTriple String
         | TargetCPU String
         | OptLevel Int
         | AddOpt Optimisation
         | RemoveOpt Optimisation
         | Client String
         | ShowOrigErr
         | AutoWidth -- ^ Automatically adjust terminal width
         | AutoSolve -- ^ Automatically issue "solve" tactic in old-style interactive prover
         | UseConsoleWidth ConsoleWidth
         | DumpHighlights
         | DesugarNats
         | NoOldTacticDeprecationWarnings -- ^ Don't show deprecation warnings for old-style tactics
         | AllowCapitalizedPatternVariables -- ^ Allow pattern variables to be capitalized
    deriving (Int -> Opt -> ShowS
[Opt] -> ShowS
Opt -> String
(Int -> Opt -> ShowS)
-> (Opt -> String) -> ([Opt] -> ShowS) -> Show Opt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Opt] -> ShowS
$cshowList :: [Opt] -> ShowS
show :: Opt -> String
$cshow :: Opt -> String
showsPrec :: Int -> Opt -> ShowS
$cshowsPrec :: Int -> Opt -> ShowS
Show, Opt -> Opt -> Bool
(Opt -> Opt -> Bool) -> (Opt -> Opt -> Bool) -> Eq Opt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Opt -> Opt -> Bool
$c/= :: Opt -> Opt -> Bool
== :: Opt -> Opt -> Bool
$c== :: Opt -> Opt -> Bool
Eq, (forall x. Opt -> Rep Opt x)
-> (forall x. Rep Opt x -> Opt) -> Generic Opt
forall x. Rep Opt x -> Opt
forall x. Opt -> Rep Opt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Opt x -> Opt
$cfrom :: forall x. Opt -> Rep Opt x
Generic)


data REPLPort = DontListen | ListenPort PortNumber
  deriving (REPLPort -> REPLPort -> Bool
(REPLPort -> REPLPort -> Bool)
-> (REPLPort -> REPLPort -> Bool) -> Eq REPLPort
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: REPLPort -> REPLPort -> Bool
$c/= :: REPLPort -> REPLPort -> Bool
== :: REPLPort -> REPLPort -> Bool
$c== :: REPLPort -> REPLPort -> Bool
Eq, (forall x. REPLPort -> Rep REPLPort x)
-> (forall x. Rep REPLPort x -> REPLPort) -> Generic REPLPort
forall x. Rep REPLPort x -> REPLPort
forall x. REPLPort -> Rep REPLPort x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep REPLPort x -> REPLPort
$cfrom :: forall x. REPLPort -> Rep REPLPort x
Generic, Int -> REPLPort -> ShowS
[REPLPort] -> ShowS
REPLPort -> String
(Int -> REPLPort -> ShowS)
-> (REPLPort -> String) -> ([REPLPort] -> ShowS) -> Show REPLPort
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [REPLPort] -> ShowS
$cshowList :: [REPLPort] -> ShowS
show :: REPLPort -> String
$cshow :: REPLPort -> String
showsPrec :: Int -> REPLPort -> ShowS
$cshowsPrec :: Int -> REPLPort -> ShowS
Show)


data Codegen = Via IRFormat String
             | Bytecode
    deriving (Int -> Codegen -> ShowS
[Codegen] -> ShowS
Codegen -> String
(Int -> Codegen -> ShowS)
-> (Codegen -> String) -> ([Codegen] -> ShowS) -> Show Codegen
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Codegen] -> ShowS
$cshowList :: [Codegen] -> ShowS
show :: Codegen -> String
$cshow :: Codegen -> String
showsPrec :: Int -> Codegen -> ShowS
$cshowsPrec :: Int -> Codegen -> ShowS
Show, Codegen -> Codegen -> Bool
(Codegen -> Codegen -> Bool)
-> (Codegen -> Codegen -> Bool) -> Eq Codegen
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Codegen -> Codegen -> Bool
$c/= :: Codegen -> Codegen -> Bool
== :: Codegen -> Codegen -> Bool
$c== :: Codegen -> Codegen -> Bool
Eq, (forall x. Codegen -> Rep Codegen x)
-> (forall x. Rep Codegen x -> Codegen) -> Generic Codegen
forall x. Rep Codegen x -> Codegen
forall x. Codegen -> Rep Codegen x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Codegen x -> Codegen
$cfrom :: forall x. Codegen -> Rep Codegen x
Generic)


data LanguageExt = TypeProviders | ErrorReflection | UniquenessTypes
                 | DSLNotation   | ElabReflection  | FCReflection
                 | LinearTypes
  deriving (Int -> LanguageExt -> ShowS
[LanguageExt] -> ShowS
LanguageExt -> String
(Int -> LanguageExt -> ShowS)
-> (LanguageExt -> String)
-> ([LanguageExt] -> ShowS)
-> Show LanguageExt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LanguageExt] -> ShowS
$cshowList :: [LanguageExt] -> ShowS
show :: LanguageExt -> String
$cshow :: LanguageExt -> String
showsPrec :: Int -> LanguageExt -> ShowS
$cshowsPrec :: Int -> LanguageExt -> ShowS
Show, LanguageExt -> LanguageExt -> Bool
(LanguageExt -> LanguageExt -> Bool)
-> (LanguageExt -> LanguageExt -> Bool) -> Eq LanguageExt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LanguageExt -> LanguageExt -> Bool
$c/= :: LanguageExt -> LanguageExt -> Bool
== :: LanguageExt -> LanguageExt -> Bool
$c== :: LanguageExt -> LanguageExt -> Bool
Eq, ReadPrec [LanguageExt]
ReadPrec LanguageExt
Int -> ReadS LanguageExt
ReadS [LanguageExt]
(Int -> ReadS LanguageExt)
-> ReadS [LanguageExt]
-> ReadPrec LanguageExt
-> ReadPrec [LanguageExt]
-> Read LanguageExt
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LanguageExt]
$creadListPrec :: ReadPrec [LanguageExt]
readPrec :: ReadPrec LanguageExt
$creadPrec :: ReadPrec LanguageExt
readList :: ReadS [LanguageExt]
$creadList :: ReadS [LanguageExt]
readsPrec :: Int -> ReadS LanguageExt
$creadsPrec :: Int -> ReadS LanguageExt
Read, Eq LanguageExt
Eq LanguageExt =>
(LanguageExt -> LanguageExt -> Ordering)
-> (LanguageExt -> LanguageExt -> Bool)
-> (LanguageExt -> LanguageExt -> Bool)
-> (LanguageExt -> LanguageExt -> Bool)
-> (LanguageExt -> LanguageExt -> Bool)
-> (LanguageExt -> LanguageExt -> LanguageExt)
-> (LanguageExt -> LanguageExt -> LanguageExt)
-> Ord LanguageExt
LanguageExt -> LanguageExt -> Bool
LanguageExt -> LanguageExt -> Ordering
LanguageExt -> LanguageExt -> LanguageExt
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LanguageExt -> LanguageExt -> LanguageExt
$cmin :: LanguageExt -> LanguageExt -> LanguageExt
max :: LanguageExt -> LanguageExt -> LanguageExt
$cmax :: LanguageExt -> LanguageExt -> LanguageExt
>= :: LanguageExt -> LanguageExt -> Bool
$c>= :: LanguageExt -> LanguageExt -> Bool
> :: LanguageExt -> LanguageExt -> Bool
$c> :: LanguageExt -> LanguageExt -> Bool
<= :: LanguageExt -> LanguageExt -> Bool
$c<= :: LanguageExt -> LanguageExt -> Bool
< :: LanguageExt -> LanguageExt -> Bool
$c< :: LanguageExt -> LanguageExt -> Bool
compare :: LanguageExt -> LanguageExt -> Ordering
$ccompare :: LanguageExt -> LanguageExt -> Ordering
$cp1Ord :: Eq LanguageExt
Ord, (forall x. LanguageExt -> Rep LanguageExt x)
-> (forall x. Rep LanguageExt x -> LanguageExt)
-> Generic LanguageExt
forall x. Rep LanguageExt x -> LanguageExt
forall x. LanguageExt -> Rep LanguageExt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LanguageExt x -> LanguageExt
$cfrom :: forall x. LanguageExt -> Rep LanguageExt x
Generic)

data IRFormat = IBCFormat | JSONFormat deriving (Int -> IRFormat -> ShowS
[IRFormat] -> ShowS
IRFormat -> String
(Int -> IRFormat -> ShowS)
-> (IRFormat -> String) -> ([IRFormat] -> ShowS) -> Show IRFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IRFormat] -> ShowS
$cshowList :: [IRFormat] -> ShowS
show :: IRFormat -> String
$cshow :: IRFormat -> String
showsPrec :: Int -> IRFormat -> ShowS
$cshowsPrec :: Int -> IRFormat -> ShowS
Show, IRFormat -> IRFormat -> Bool
(IRFormat -> IRFormat -> Bool)
-> (IRFormat -> IRFormat -> Bool) -> Eq IRFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IRFormat -> IRFormat -> Bool
$c/= :: IRFormat -> IRFormat -> Bool
== :: IRFormat -> IRFormat -> Bool
$c== :: IRFormat -> IRFormat -> Bool
Eq, (forall x. IRFormat -> Rep IRFormat x)
-> (forall x. Rep IRFormat x -> IRFormat) -> Generic IRFormat
forall x. Rep IRFormat x -> IRFormat
forall x. IRFormat -> Rep IRFormat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IRFormat x -> IRFormat
$cfrom :: forall x. IRFormat -> Rep IRFormat x
Generic)


-- | How wide is the console?
data ConsoleWidth = InfinitelyWide -- ^ Have pretty-printer assume that lines should not be broken
                  | ColsWide Int   -- ^ Manually specified - must be positive
                  | AutomaticWidth -- ^ Attempt to determine width, or 80 otherwise
   deriving (Int -> ConsoleWidth -> ShowS
[ConsoleWidth] -> ShowS
ConsoleWidth -> String
(Int -> ConsoleWidth -> ShowS)
-> (ConsoleWidth -> String)
-> ([ConsoleWidth] -> ShowS)
-> Show ConsoleWidth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConsoleWidth] -> ShowS
$cshowList :: [ConsoleWidth] -> ShowS
show :: ConsoleWidth -> String
$cshow :: ConsoleWidth -> String
showsPrec :: Int -> ConsoleWidth -> ShowS
$cshowsPrec :: Int -> ConsoleWidth -> ShowS
Show, ConsoleWidth -> ConsoleWidth -> Bool
(ConsoleWidth -> ConsoleWidth -> Bool)
-> (ConsoleWidth -> ConsoleWidth -> Bool) -> Eq ConsoleWidth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConsoleWidth -> ConsoleWidth -> Bool
$c/= :: ConsoleWidth -> ConsoleWidth -> Bool
== :: ConsoleWidth -> ConsoleWidth -> Bool
$c== :: ConsoleWidth -> ConsoleWidth -> Bool
Eq, (forall x. ConsoleWidth -> Rep ConsoleWidth x)
-> (forall x. Rep ConsoleWidth x -> ConsoleWidth)
-> Generic ConsoleWidth
forall x. Rep ConsoleWidth x -> ConsoleWidth
forall x. ConsoleWidth -> Rep ConsoleWidth x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConsoleWidth x -> ConsoleWidth
$cfrom :: forall x. ConsoleWidth -> Rep ConsoleWidth x
Generic)

data HowMuchDocs = FullDocs | OverviewDocs

data OutputFmt = HTMLOutput | LaTeXOutput

data Optimisation = PETransform | GeneralisedNatHack -- ^ partial eval and associated transforms
  deriving (Int -> Optimisation -> ShowS
[Optimisation] -> ShowS
Optimisation -> String
(Int -> Optimisation -> ShowS)
-> (Optimisation -> String)
-> ([Optimisation] -> ShowS)
-> Show Optimisation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Optimisation] -> ShowS
$cshowList :: [Optimisation] -> ShowS
show :: Optimisation -> String
$cshow :: Optimisation -> String
showsPrec :: Int -> Optimisation -> ShowS
$cshowsPrec :: Int -> Optimisation -> ShowS
Show, Optimisation -> Optimisation -> Bool
(Optimisation -> Optimisation -> Bool)
-> (Optimisation -> Optimisation -> Bool) -> Eq Optimisation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Optimisation -> Optimisation -> Bool
$c/= :: Optimisation -> Optimisation -> Bool
== :: Optimisation -> Optimisation -> Bool
$c== :: Optimisation -> Optimisation -> Bool
Eq, (forall x. Optimisation -> Rep Optimisation x)
-> (forall x. Rep Optimisation x -> Optimisation)
-> Generic Optimisation
forall x. Rep Optimisation x -> Optimisation
forall x. Optimisation -> Rep Optimisation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Optimisation x -> Optimisation
$cfrom :: forall x. Optimisation -> Rep Optimisation x
Generic)

-- | Recognised logging categories for the Idris compiler.
--
-- @TODO add in sub categories.
data LogCat = IParse
            | IElab
            | ICodeGen
            | IErasure
            | ICoverage
            | IIBC
            deriving (Int -> LogCat -> ShowS
[LogCat] -> ShowS
LogCat -> String
(Int -> LogCat -> ShowS)
-> (LogCat -> String) -> ([LogCat] -> ShowS) -> Show LogCat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LogCat] -> ShowS
$cshowList :: [LogCat] -> ShowS
show :: LogCat -> String
$cshow :: LogCat -> String
showsPrec :: Int -> LogCat -> ShowS
$cshowsPrec :: Int -> LogCat -> ShowS
Show, LogCat -> LogCat -> Bool
(LogCat -> LogCat -> Bool)
-> (LogCat -> LogCat -> Bool) -> Eq LogCat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LogCat -> LogCat -> Bool
$c/= :: LogCat -> LogCat -> Bool
== :: LogCat -> LogCat -> Bool
$c== :: LogCat -> LogCat -> Bool
Eq, Eq LogCat
Eq LogCat =>
(LogCat -> LogCat -> Ordering)
-> (LogCat -> LogCat -> Bool)
-> (LogCat -> LogCat -> Bool)
-> (LogCat -> LogCat -> Bool)
-> (LogCat -> LogCat -> Bool)
-> (LogCat -> LogCat -> LogCat)
-> (LogCat -> LogCat -> LogCat)
-> Ord LogCat
LogCat -> LogCat -> Bool
LogCat -> LogCat -> Ordering
LogCat -> LogCat -> LogCat
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LogCat -> LogCat -> LogCat
$cmin :: LogCat -> LogCat -> LogCat
max :: LogCat -> LogCat -> LogCat
$cmax :: LogCat -> LogCat -> LogCat
>= :: LogCat -> LogCat -> Bool
$c>= :: LogCat -> LogCat -> Bool
> :: LogCat -> LogCat -> Bool
$c> :: LogCat -> LogCat -> Bool
<= :: LogCat -> LogCat -> Bool
$c<= :: LogCat -> LogCat -> Bool
< :: LogCat -> LogCat -> Bool
$c< :: LogCat -> LogCat -> Bool
compare :: LogCat -> LogCat -> Ordering
$ccompare :: LogCat -> LogCat -> Ordering
$cp1Ord :: Eq LogCat
Ord, (forall x. LogCat -> Rep LogCat x)
-> (forall x. Rep LogCat x -> LogCat) -> Generic LogCat
forall x. Rep LogCat x -> LogCat
forall x. LogCat -> Rep LogCat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LogCat x -> LogCat
$cfrom :: forall x. LogCat -> Rep LogCat x
Generic)

strLogCat :: LogCat -> String
strLogCat :: LogCat -> String
strLogCat IParse    = "parser"
strLogCat IElab     = "elab"
strLogCat ICodeGen  = "codegen"
strLogCat IErasure  = "erasure"
strLogCat ICoverage = "coverage"
strLogCat IIBC      = "ibc"

codegenCats :: [LogCat]
codegenCats :: [LogCat]
codegenCats =  [LogCat
ICodeGen]

parserCats :: [LogCat]
parserCats :: [LogCat]
parserCats = [LogCat
IParse]

elabCats :: [LogCat]
elabCats :: [LogCat]
elabCats = [LogCat
IElab]

loggingCatsStr :: String
loggingCatsStr :: String
loggingCatsStr = [String] -> String
unlines
    [ (LogCat -> String
strLogCat LogCat
IParse)
    , (LogCat -> String
strLogCat LogCat
IElab)
    , (LogCat -> String
strLogCat LogCat
ICodeGen)
    , (LogCat -> String
strLogCat LogCat
IErasure)
    , (LogCat -> String
strLogCat LogCat
ICoverage)
    , (LogCat -> String
strLogCat LogCat
IIBC)
    ]

getFile :: Opt -> Maybe String
getFile :: Opt -> Maybe String
getFile (Filename s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getFile _ = Maybe String
forall a. Maybe a
Nothing

getBC :: Opt -> Maybe String
getBC :: Opt -> Maybe String
getBC (BCAsm s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getBC _ = Maybe String
forall a. Maybe a
Nothing

getOutput :: Opt -> Maybe String
getOutput :: Opt -> Maybe String
getOutput (Output s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getOutput _ = Maybe String
forall a. Maybe a
Nothing

getIBCSubDir :: Opt -> Maybe String
getIBCSubDir :: Opt -> Maybe String
getIBCSubDir (IBCSubDir s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getIBCSubDir _ = Maybe String
forall a. Maybe a
Nothing

getImportDir :: Opt -> Maybe String
getImportDir :: Opt -> Maybe String
getImportDir (ImportDir s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getImportDir _ = Maybe String
forall a. Maybe a
Nothing

getSourceDir :: Opt -> Maybe String
getSourceDir :: Opt -> Maybe String
getSourceDir (SourceDir s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getSourceDir _ = Maybe String
forall a. Maybe a
Nothing

getPkgDir :: Opt -> Maybe String
getPkgDir :: Opt -> Maybe String
getPkgDir (Pkg s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getPkgDir _ = Maybe String
forall a. Maybe a
Nothing

getPkg :: Opt -> Maybe (Bool, String)
getPkg :: Opt -> Maybe (Bool, String)
getPkg (PkgBuild s :: String
s)   = (Bool, String) -> Maybe (Bool, String)
forall a. a -> Maybe a
Just (Bool
False, String
s)
getPkg (PkgInstall s :: String
s) = (Bool, String) -> Maybe (Bool, String)
forall a. a -> Maybe a
Just (Bool
True, String
s)
getPkg _ = Maybe (Bool, String)
forall a. Maybe a
Nothing

getPkgClean :: Opt -> Maybe String
getPkgClean :: Opt -> Maybe String
getPkgClean (PkgClean s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getPkgClean _ = Maybe String
forall a. Maybe a
Nothing

getPkgREPL :: Opt -> Maybe String
getPkgREPL :: Opt -> Maybe String
getPkgREPL (PkgREPL s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getPkgREPL _ = Maybe String
forall a. Maybe a
Nothing

getPkgCheck :: Opt -> Maybe String
getPkgCheck :: Opt -> Maybe String
getPkgCheck (PkgCheck s :: String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getPkgCheck _              = Maybe String
forall a. Maybe a
Nothing

-- | Returns None if given an Opt which is not PkgMkDoc
--   Otherwise returns Just x, where x is the contents of PkgMkDoc
getPkgMkDoc :: Opt                  -- ^ Opt to extract
            -> Maybe (Bool, String) -- ^ Result
getPkgMkDoc :: Opt -> Maybe (Bool, String)
getPkgMkDoc (PkgDocBuild  str :: String
str)  = (Bool, String) -> Maybe (Bool, String)
forall a. a -> Maybe a
Just (Bool
False,String
str)
getPkgMkDoc (PkgDocInstall str :: String
str) = (Bool, String) -> Maybe (Bool, String)
forall a. a -> Maybe a
Just (Bool
True,String
str)
getPkgMkDoc _              = Maybe (Bool, String)
forall a. Maybe a
Nothing

getPkgTest :: Opt          -- ^ the option to extract
           -> Maybe String -- ^ the package file to test
getPkgTest :: Opt -> Maybe String
getPkgTest (PkgTest f :: String
f) = String -> Maybe String
forall a. a -> Maybe a
Just String
f
getPkgTest _ = Maybe String
forall a. Maybe a
Nothing

getCodegen :: Opt -> Maybe Codegen
getCodegen :: Opt -> Maybe Codegen
getCodegen (UseCodegen x :: Codegen
x) = Codegen -> Maybe Codegen
forall a. a -> Maybe a
Just Codegen
x
getCodegen _ = Maybe Codegen
forall a. Maybe a
Nothing

getCodegenArgs :: Opt -> Maybe String
getCodegenArgs :: Opt -> Maybe String
getCodegenArgs (CodegenArgs args :: String
args) = String -> Maybe String
forall a. a -> Maybe a
Just String
args
getCodegenArgs _ = Maybe String
forall a. Maybe a
Nothing

getConsoleWidth :: Opt -> Maybe ConsoleWidth
getConsoleWidth :: Opt -> Maybe ConsoleWidth
getConsoleWidth (UseConsoleWidth x :: ConsoleWidth
x) = ConsoleWidth -> Maybe ConsoleWidth
forall a. a -> Maybe a
Just ConsoleWidth
x
getConsoleWidth _ = Maybe ConsoleWidth
forall a. Maybe a
Nothing

getExecScript :: Opt -> Maybe String
getExecScript :: Opt -> Maybe String
getExecScript (InterpretScript expr :: String
expr) = String -> Maybe String
forall a. a -> Maybe a
Just String
expr
getExecScript _ = Maybe String
forall a. Maybe a
Nothing

getPkgIndex :: Opt -> Maybe FilePath
getPkgIndex :: Opt -> Maybe String
getPkgIndex (PkgIndex file :: String
file) = String -> Maybe String
forall a. a -> Maybe a
Just String
file
getPkgIndex _ = Maybe String
forall a. Maybe a
Nothing

getEvalExpr :: Opt -> Maybe String
getEvalExpr :: Opt -> Maybe String
getEvalExpr (EvalExpr expr :: String
expr) = String -> Maybe String
forall a. a -> Maybe a
Just String
expr
getEvalExpr _ = Maybe String
forall a. Maybe a
Nothing

getOutputTy :: Opt -> Maybe OutputType
getOutputTy :: Opt -> Maybe OutputType
getOutputTy (OutputTy t :: OutputType
t) = OutputType -> Maybe OutputType
forall a. a -> Maybe a
Just OutputType
t
getOutputTy _ = Maybe OutputType
forall a. Maybe a
Nothing

getLanguageExt :: Opt -> Maybe LanguageExt
getLanguageExt :: Opt -> Maybe LanguageExt
getLanguageExt (Extension e :: LanguageExt
e) = LanguageExt -> Maybe LanguageExt
forall a. a -> Maybe a
Just LanguageExt
e
getLanguageExt _ = Maybe LanguageExt
forall a. Maybe a
Nothing

getTriple :: Opt -> Maybe String
getTriple :: Opt -> Maybe String
getTriple (TargetTriple x :: String
x) = String -> Maybe String
forall a. a -> Maybe a
Just String
x
getTriple _ = Maybe String
forall a. Maybe a
Nothing

getCPU :: Opt -> Maybe String
getCPU :: Opt -> Maybe String
getCPU (TargetCPU x :: String
x) = String -> Maybe String
forall a. a -> Maybe a
Just String
x
getCPU _ = Maybe String
forall a. Maybe a
Nothing

getOptLevel :: Opt -> Maybe Int
getOptLevel :: Opt -> Maybe Int
getOptLevel (OptLevel x :: Int
x) = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
x
getOptLevel _ = Maybe Int
forall a. Maybe a
Nothing

getOptimisation :: Opt -> Maybe (Bool,Optimisation)
getOptimisation :: Opt -> Maybe (Bool, Optimisation)
getOptimisation (AddOpt p :: Optimisation
p)    = (Bool, Optimisation) -> Maybe (Bool, Optimisation)
forall a. a -> Maybe a
Just (Bool
True,  Optimisation
p)
getOptimisation (RemoveOpt p :: Optimisation
p) = (Bool, Optimisation) -> Maybe (Bool, Optimisation)
forall a. a -> Maybe a
Just (Bool
False, Optimisation
p)
getOptimisation _             = Maybe (Bool, Optimisation)
forall a. Maybe a
Nothing

getColour :: Opt -> Maybe Bool
getColour :: Opt -> Maybe Bool
getColour (ColourREPL b :: Bool
b) = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
b
getColour _ = Maybe Bool
forall a. Maybe a
Nothing

getClient :: Opt -> Maybe String
getClient :: Opt -> Maybe String
getClient (Client x :: String
x) = String -> Maybe String
forall a. a -> Maybe a
Just String
x
getClient _ = Maybe String
forall a. Maybe a
Nothing

-- Get the first valid port
getPort :: [Opt] -> Maybe REPLPort
getPort :: [Opt] -> Maybe REPLPort
getPort []            = Maybe REPLPort
forall a. Maybe a
Nothing
getPort (Port p :: REPLPort
p : _ ) = REPLPort -> Maybe REPLPort
forall a. a -> Maybe a
Just REPLPort
p
getPort (_      : xs :: [Opt]
xs) = [Opt] -> Maybe REPLPort
getPort [Opt]
xs

opt :: (Opt -> Maybe a) -> [Opt] -> [a]
opt :: (Opt -> Maybe a) -> [Opt] -> [a]
opt = (Opt -> Maybe a) -> [Opt] -> [a]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe