{-|
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
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
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. 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
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. 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
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
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
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. 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
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
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]
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
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
Ord, 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
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
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. 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
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
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. 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
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
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. 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
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
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
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
Ord, 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 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) = forall a. a -> Maybe a
Just String
s
getFile Opt
_ = forall a. Maybe a
Nothing

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- Get the first valid port
getPort :: [Opt] -> Maybe REPLPort
getPort :: [Opt] -> Maybe REPLPort
getPort []            = forall a. Maybe a
Nothing
getPort (Port REPLPort
p : [Opt]
_ ) = 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 = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe