{-|
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
$cshowsPrec :: Int -> Opt -> ShowS
showsPrec :: Int -> Opt -> ShowS
$cshow :: Opt -> String
show :: Opt -> String
$cshowList :: [Opt] -> ShowS
showList :: [Opt] -> ShowS
Show, Opt -> Opt -> Bool
(Opt -> Opt -> Bool) -> (Opt -> Opt -> Bool) -> Eq Opt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Opt -> Opt -> Bool
== :: Opt -> Opt -> Bool
$c/= :: Opt -> Opt -> Bool
/= :: 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
$cfrom :: forall x. Opt -> Rep Opt x
from :: forall x. Opt -> Rep Opt x
$cto :: forall x. Rep Opt x -> Opt
to :: forall x. Rep Opt x -> Opt
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
$c== :: REPLPort -> REPLPort -> Bool
== :: REPLPort -> REPLPort -> Bool
$c/= :: REPLPort -> REPLPort -> Bool
/= :: 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
$cfrom :: forall x. REPLPort -> Rep REPLPort x
from :: forall x. REPLPort -> Rep REPLPort x
$cto :: forall x. Rep REPLPort x -> REPLPort
to :: forall x. Rep REPLPort x -> REPLPort
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
$cshowsPrec :: Int -> REPLPort -> ShowS
showsPrec :: Int -> REPLPort -> ShowS
$cshow :: REPLPort -> String
show :: REPLPort -> String
$cshowList :: [REPLPort] -> ShowS
showList :: [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
$cshowsPrec :: Int -> Codegen -> ShowS
showsPrec :: Int -> Codegen -> ShowS
$cshow :: Codegen -> String
show :: Codegen -> String
$cshowList :: [Codegen] -> ShowS
showList :: [Codegen] -> ShowS
Show, Codegen -> Codegen -> Bool
(Codegen -> Codegen -> Bool)
-> (Codegen -> Codegen -> Bool) -> Eq Codegen
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Codegen -> Codegen -> Bool
== :: Codegen -> Codegen -> Bool
$c/= :: Codegen -> Codegen -> Bool
/= :: 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
$cfrom :: forall x. Codegen -> Rep Codegen x
from :: forall x. Codegen -> Rep Codegen x
$cto :: forall x. Rep Codegen x -> Codegen
to :: forall x. Rep Codegen x -> Codegen
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
$cshowsPrec :: Int -> LanguageExt -> ShowS
showsPrec :: Int -> LanguageExt -> ShowS
$cshow :: LanguageExt -> String
show :: LanguageExt -> String
$cshowList :: [LanguageExt] -> ShowS
showList :: [LanguageExt] -> ShowS
Show, LanguageExt -> LanguageExt -> Bool
(LanguageExt -> LanguageExt -> Bool)
-> (LanguageExt -> LanguageExt -> Bool) -> Eq LanguageExt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LanguageExt -> LanguageExt -> Bool
== :: LanguageExt -> LanguageExt -> Bool
$c/= :: LanguageExt -> LanguageExt -> Bool
/= :: 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
$creadsPrec :: Int -> ReadS LanguageExt
readsPrec :: Int -> ReadS LanguageExt
$creadList :: ReadS [LanguageExt]
readList :: ReadS [LanguageExt]
$creadPrec :: ReadPrec LanguageExt
readPrec :: ReadPrec LanguageExt
$creadListPrec :: ReadPrec [LanguageExt]
readListPrec :: ReadPrec [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
$ccompare :: LanguageExt -> LanguageExt -> Ordering
compare :: LanguageExt -> LanguageExt -> Ordering
$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
>= :: LanguageExt -> LanguageExt -> Bool
$cmax :: LanguageExt -> LanguageExt -> LanguageExt
max :: LanguageExt -> LanguageExt -> LanguageExt
$cmin :: LanguageExt -> LanguageExt -> LanguageExt
min :: LanguageExt -> LanguageExt -> 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
$cfrom :: forall x. LanguageExt -> Rep LanguageExt x
from :: forall x. LanguageExt -> Rep LanguageExt x
$cto :: forall x. Rep LanguageExt x -> LanguageExt
to :: forall x. Rep LanguageExt x -> LanguageExt
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
$cshowsPrec :: Int -> IRFormat -> ShowS
showsPrec :: Int -> IRFormat -> ShowS
$cshow :: IRFormat -> String
show :: IRFormat -> String
$cshowList :: [IRFormat] -> ShowS
showList :: [IRFormat] -> ShowS
Show, IRFormat -> IRFormat -> Bool
(IRFormat -> IRFormat -> Bool)
-> (IRFormat -> IRFormat -> Bool) -> Eq IRFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IRFormat -> IRFormat -> Bool
== :: IRFormat -> IRFormat -> Bool
$c/= :: IRFormat -> IRFormat -> Bool
/= :: 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
$cfrom :: forall x. IRFormat -> Rep IRFormat x
from :: forall x. IRFormat -> Rep IRFormat x
$cto :: forall x. Rep IRFormat x -> IRFormat
to :: forall x. Rep IRFormat x -> IRFormat
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
$cshowsPrec :: Int -> ConsoleWidth -> ShowS
showsPrec :: Int -> ConsoleWidth -> ShowS
$cshow :: ConsoleWidth -> String
show :: ConsoleWidth -> String
$cshowList :: [ConsoleWidth] -> ShowS
showList :: [ConsoleWidth] -> ShowS
Show, ConsoleWidth -> ConsoleWidth -> Bool
(ConsoleWidth -> ConsoleWidth -> Bool)
-> (ConsoleWidth -> ConsoleWidth -> Bool) -> Eq ConsoleWidth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConsoleWidth -> ConsoleWidth -> Bool
== :: ConsoleWidth -> ConsoleWidth -> Bool
$c/= :: ConsoleWidth -> ConsoleWidth -> Bool
/= :: 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
$cfrom :: forall x. ConsoleWidth -> Rep ConsoleWidth x
from :: forall x. ConsoleWidth -> Rep ConsoleWidth x
$cto :: forall x. Rep ConsoleWidth x -> ConsoleWidth
to :: forall x. Rep ConsoleWidth x -> ConsoleWidth
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
$cshowsPrec :: Int -> Optimisation -> ShowS
showsPrec :: Int -> Optimisation -> ShowS
$cshow :: Optimisation -> String
show :: Optimisation -> String
$cshowList :: [Optimisation] -> ShowS
showList :: [Optimisation] -> ShowS
Show, Optimisation -> Optimisation -> Bool
(Optimisation -> Optimisation -> Bool)
-> (Optimisation -> Optimisation -> Bool) -> Eq Optimisation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Optimisation -> Optimisation -> Bool
== :: Optimisation -> Optimisation -> Bool
$c/= :: Optimisation -> Optimisation -> Bool
/= :: 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
$cfrom :: forall x. Optimisation -> Rep Optimisation x
from :: forall x. Optimisation -> Rep Optimisation x
$cto :: forall x. Rep Optimisation x -> Optimisation
to :: forall x. Rep Optimisation x -> Optimisation
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
$cshowsPrec :: Int -> LogCat -> ShowS
showsPrec :: Int -> LogCat -> ShowS
$cshow :: LogCat -> String
show :: LogCat -> String
$cshowList :: [LogCat] -> ShowS
showList :: [LogCat] -> ShowS
Show, LogCat -> LogCat -> Bool
(LogCat -> LogCat -> Bool)
-> (LogCat -> LogCat -> Bool) -> Eq LogCat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LogCat -> LogCat -> Bool
== :: LogCat -> LogCat -> Bool
$c/= :: LogCat -> LogCat -> Bool
/= :: 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
$ccompare :: LogCat -> LogCat -> Ordering
compare :: LogCat -> LogCat -> Ordering
$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
>= :: LogCat -> LogCat -> Bool
$cmax :: LogCat -> LogCat -> LogCat
max :: LogCat -> LogCat -> LogCat
$cmin :: LogCat -> LogCat -> LogCat
min :: LogCat -> LogCat -> 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
$cfrom :: forall x. LogCat -> Rep LogCat x
from :: forall x. LogCat -> Rep LogCat x
$cto :: forall x. Rep LogCat x -> LogCat
to :: forall x. Rep LogCat x -> LogCat
Generic)

strLogCat :: LogCat -> String
strLogCat :: LogCat -> String
strLogCat LogCat
IParse    = String
"parser"
strLogCat LogCat
IElab     = String
"elab"
strLogCat LogCat
ICodeGen  = String
"codegen"
strLogCat LogCat
IErasure  = String
"erasure"
strLogCat LogCat
ICoverage = String
"coverage"
strLogCat LogCat
IIBC      = String
"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 String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getFile Opt
_ = Maybe String
forall a. Maybe a
Nothing

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

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

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

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

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

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

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

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

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

getPkgCheck :: Opt -> Maybe String
getPkgCheck :: Opt -> Maybe String
getPkgCheck (PkgCheck String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getPkgCheck Opt
_              = 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  String
str)  = (Bool, String) -> Maybe (Bool, String)
forall a. a -> Maybe a
Just (Bool
False,String
str)
getPkgMkDoc (PkgDocInstall String
str) = (Bool, String) -> Maybe (Bool, String)
forall a. a -> Maybe a
Just (Bool
True,String
str)
getPkgMkDoc Opt
_              = 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 String
f) = String -> Maybe String
forall a. a -> Maybe a
Just String
f
getPkgTest Opt
_ = Maybe String
forall a. Maybe a
Nothing

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

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

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

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

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

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

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

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

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

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

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

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

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

getClient :: Opt -> Maybe String
getClient :: Opt -> Maybe String
getClient (Client String
x) = String -> Maybe String
forall a. a -> Maybe a
Just String
x
getClient Opt
_ = 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 REPLPort
p : [Opt]
_ ) = REPLPort -> Maybe REPLPort
forall a. a -> Maybe a
Just REPLPort
p
getPort (Opt
_      : [Opt]
xs) = [Opt] -> Maybe REPLPort
getPort [Opt]
xs

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