2022-05-30 14:40:52 +03:00
|
|
|
module GlobalOptions
|
|
|
|
( module GlobalOptions,
|
|
|
|
)
|
|
|
|
where
|
2022-05-18 18:10:10 +03:00
|
|
|
|
2022-06-09 17:36:07 +03:00
|
|
|
import Commands.Extra
|
2022-09-12 11:44:00 +03:00
|
|
|
import Juvix.Compiler.Abstract.Pretty.Options qualified as Abstract
|
|
|
|
import Juvix.Compiler.Internal.Pretty.Options qualified as Internal
|
2022-09-01 14:22:32 +03:00
|
|
|
import Juvix.Data.Error.GenericError qualified as E
|
2022-07-08 14:59:45 +03:00
|
|
|
import Juvix.Prelude
|
2022-06-09 17:36:07 +03:00
|
|
|
import Options.Applicative hiding (hidden)
|
2022-05-18 18:10:10 +03:00
|
|
|
|
|
|
|
data GlobalOptions = GlobalOptions
|
|
|
|
{ _globalNoColors :: Bool,
|
|
|
|
_globalShowNameIds :: Bool,
|
2022-05-30 14:40:52 +03:00
|
|
|
_globalOnlyErrors :: Bool,
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin :: Bool,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalNoTermination :: Bool,
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity :: Bool,
|
2022-06-30 12:31:08 +03:00
|
|
|
_globalNoStdlib :: Bool,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalInputFiles :: [FilePath]
|
2022-05-18 18:10:10 +03:00
|
|
|
}
|
2022-05-30 14:40:52 +03:00
|
|
|
deriving stock (Eq, Show)
|
2022-05-18 18:10:10 +03:00
|
|
|
|
|
|
|
makeLenses ''GlobalOptions
|
|
|
|
|
2022-09-12 11:44:00 +03:00
|
|
|
instance CanonicalProjection GlobalOptions Internal.Options where
|
|
|
|
project g =
|
|
|
|
Internal.Options
|
|
|
|
{ Internal._optShowNameIds = g ^. globalShowNameIds
|
|
|
|
}
|
|
|
|
|
|
|
|
instance CanonicalProjection GlobalOptions Abstract.Options where
|
|
|
|
project g =
|
|
|
|
Abstract.defaultOptions
|
|
|
|
{ Abstract._optShowNameIds = g ^. globalShowNameIds
|
|
|
|
}
|
|
|
|
|
2022-06-09 17:36:07 +03:00
|
|
|
defaultGlobalOptions :: GlobalOptions
|
|
|
|
defaultGlobalOptions =
|
|
|
|
GlobalOptions
|
|
|
|
{ _globalNoColors = False,
|
|
|
|
_globalShowNameIds = False,
|
|
|
|
_globalOnlyErrors = False,
|
|
|
|
_globalNoTermination = False,
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin = False,
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity = False,
|
2022-06-30 12:31:08 +03:00
|
|
|
_globalNoStdlib = False,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalInputFiles = []
|
|
|
|
}
|
|
|
|
|
|
|
|
instance Semigroup GlobalOptions where
|
|
|
|
o1 <> o2 =
|
|
|
|
GlobalOptions
|
|
|
|
{ _globalNoColors = o1 ^. globalNoColors || o2 ^. globalNoColors,
|
|
|
|
_globalShowNameIds = o1 ^. globalShowNameIds || o2 ^. globalShowNameIds,
|
|
|
|
_globalOnlyErrors = o1 ^. globalOnlyErrors || o2 ^. globalOnlyErrors,
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin = o1 ^. globalStdin || o2 ^. globalStdin,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalNoTermination = o1 ^. globalNoTermination || o2 ^. globalNoTermination,
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity = o1 ^. globalNoPositivity || o2 ^. globalNoPositivity,
|
2022-06-30 12:31:08 +03:00
|
|
|
_globalNoStdlib = o1 ^. globalNoStdlib || o2 ^. globalNoStdlib,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalInputFiles = o1 ^. globalInputFiles ++ o2 ^. globalInputFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
instance Monoid GlobalOptions where
|
|
|
|
mempty = defaultGlobalOptions
|
|
|
|
mappend = (<>)
|
|
|
|
|
|
|
|
-- | Get a parser for global flags which can be hidden or not depending on
|
|
|
|
-- the input boolean
|
|
|
|
parseGlobalFlags :: Bool -> Parser GlobalOptions
|
|
|
|
parseGlobalFlags b = do
|
2022-05-18 18:10:10 +03:00
|
|
|
_globalNoColors <-
|
|
|
|
switch
|
|
|
|
( long "no-colors"
|
2022-06-09 17:36:07 +03:00
|
|
|
<> help "Disable ANSI formatting"
|
|
|
|
<> hidden b
|
2022-05-18 18:10:10 +03:00
|
|
|
)
|
|
|
|
_globalShowNameIds <-
|
|
|
|
switch
|
|
|
|
( long "show-name-ids"
|
|
|
|
<> help "Show the unique number of each identifier when pretty printing"
|
2022-06-09 17:36:07 +03:00
|
|
|
<> hidden b
|
2022-05-18 18:10:10 +03:00
|
|
|
)
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin <-
|
|
|
|
switch
|
|
|
|
( long "stdin"
|
|
|
|
<> help "Read from Stdin"
|
|
|
|
<> hidden b
|
|
|
|
)
|
2022-05-18 18:10:10 +03:00
|
|
|
_globalOnlyErrors <-
|
|
|
|
switch
|
|
|
|
( long "only-errors"
|
2022-07-08 14:59:45 +03:00
|
|
|
<> help "Only print errors in a uniform format (used by juvix-mode)"
|
2022-06-09 17:36:07 +03:00
|
|
|
<> hidden b
|
2022-05-18 18:10:10 +03:00
|
|
|
)
|
2022-05-30 14:40:52 +03:00
|
|
|
_globalNoTermination <-
|
|
|
|
switch
|
|
|
|
( long "no-termination"
|
2022-06-09 17:36:07 +03:00
|
|
|
<> help "Disable termination checking"
|
|
|
|
<> hidden b
|
2022-05-30 14:40:52 +03:00
|
|
|
)
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity <-
|
|
|
|
switch
|
|
|
|
( long "no-positivity"
|
|
|
|
<> help "Disable positivity checking for inductive types"
|
|
|
|
<> hidden b
|
|
|
|
)
|
2022-06-30 12:31:08 +03:00
|
|
|
_globalNoStdlib <-
|
|
|
|
switch
|
|
|
|
( long "no-stdlib"
|
|
|
|
<> help "Do not use the standard library"
|
|
|
|
<> hidden b
|
|
|
|
)
|
2022-06-09 17:36:07 +03:00
|
|
|
return GlobalOptions {_globalInputFiles = [], ..}
|
|
|
|
|
|
|
|
parseGlobalOptions :: Bool -> Parser GlobalOptions
|
|
|
|
parseGlobalOptions b = do
|
|
|
|
opts <- parseGlobalFlags b
|
|
|
|
files <- parserInputFiles
|
|
|
|
return opts {_globalInputFiles = files}
|
2022-09-01 14:22:32 +03:00
|
|
|
|
|
|
|
genericFromGlobalOptions :: GlobalOptions -> E.GenericOptions
|
|
|
|
genericFromGlobalOptions GlobalOptions {..} = E.GenericOptions {E._showNameIds = _globalShowNameIds}
|