2022-05-30 14:40:52 +03:00
|
|
|
module GlobalOptions
|
|
|
|
( module GlobalOptions,
|
|
|
|
)
|
|
|
|
where
|
2022-05-18 18:10:10 +03:00
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
import CommonOptions
|
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
|
2023-01-06 19:54:13 +03:00
|
|
|
import Juvix.Extra.Paths
|
2022-05-18 18:10:10 +03:00
|
|
|
|
|
|
|
data GlobalOptions = GlobalOptions
|
|
|
|
{ _globalNoColors :: Bool,
|
|
|
|
_globalShowNameIds :: Bool,
|
2023-01-06 19:54:13 +03:00
|
|
|
_globalBuildDir :: Maybe (AppPath Dir),
|
2022-05-30 14:40:52 +03:00
|
|
|
_globalOnlyErrors :: Bool,
|
2022-10-18 18:38:31 +03:00
|
|
|
_globalNoApe :: 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-12-20 15:05:40 +03:00
|
|
|
_globalNoStdlib :: Bool
|
2022-05-18 18:10:10 +03:00
|
|
|
}
|
2022-12-20 15:05:40 +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-09-14 17:16:15 +03:00
|
|
|
instance CanonicalProjection GlobalOptions E.GenericOptions where
|
2022-10-18 18:38:31 +03:00
|
|
|
project GlobalOptions {..} =
|
|
|
|
E.GenericOptions
|
|
|
|
{ E._showNameIds = _globalShowNameIds,
|
|
|
|
E._genericNoApe = _globalNoApe
|
|
|
|
}
|
2022-09-14 17:16:15 +03:00
|
|
|
|
2022-06-09 17:36:07 +03:00
|
|
|
defaultGlobalOptions :: GlobalOptions
|
|
|
|
defaultGlobalOptions =
|
|
|
|
GlobalOptions
|
|
|
|
{ _globalNoColors = False,
|
|
|
|
_globalShowNameIds = False,
|
|
|
|
_globalOnlyErrors = False,
|
2022-10-18 18:38:31 +03:00
|
|
|
_globalNoApe = False,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalNoTermination = False,
|
2023-01-06 19:54:13 +03:00
|
|
|
_globalBuildDir = Nothing,
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin = False,
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity = False,
|
2022-12-20 15:05:40 +03:00
|
|
|
_globalNoStdlib = False
|
2022-06-09 17:36:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
-- | Get a parser for global flags which can be hidden or not depending on
|
|
|
|
-- the input boolean
|
2022-09-14 17:16:15 +03:00
|
|
|
parseGlobalFlags :: Parser GlobalOptions
|
|
|
|
parseGlobalFlags = 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"
|
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"
|
|
|
|
)
|
2023-01-06 19:54:13 +03:00
|
|
|
_globalBuildDir <-
|
|
|
|
optional
|
2023-01-09 17:09:02 +03:00
|
|
|
( parseBuildDir
|
|
|
|
( long "internal-build-dir"
|
|
|
|
<> help "Directory for compiler internal output"
|
2023-01-06 19:54:13 +03:00
|
|
|
)
|
|
|
|
)
|
2022-10-18 18:38:31 +03:00
|
|
|
_globalNoApe <-
|
|
|
|
switch
|
|
|
|
( long "no-format"
|
2023-01-09 17:09:02 +03:00
|
|
|
<> help "Disable the new pretty printing algorithm"
|
2022-10-18 18:38:31 +03:00
|
|
|
)
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin <-
|
|
|
|
switch
|
|
|
|
( long "stdin"
|
|
|
|
<> help "Read from Stdin"
|
|
|
|
)
|
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-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"
|
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"
|
|
|
|
)
|
2022-06-30 12:31:08 +03:00
|
|
|
_globalNoStdlib <-
|
|
|
|
switch
|
|
|
|
( long "no-stdlib"
|
|
|
|
<> help "Do not use the standard library"
|
|
|
|
)
|
2022-09-14 17:16:15 +03:00
|
|
|
return GlobalOptions {..}
|
2023-01-09 17:09:02 +03:00
|
|
|
|
|
|
|
parseBuildDir :: Mod OptionFields (SomeBase Dir) -> Parser (AppPath Dir)
|
|
|
|
parseBuildDir m = do
|
|
|
|
_pathPath <-
|
|
|
|
option
|
|
|
|
someDirOpt
|
|
|
|
( value (Rel relBuildDir)
|
|
|
|
<> metavar "BUILD_DIR"
|
|
|
|
<> action "directory"
|
|
|
|
<> showDefault
|
|
|
|
<> m
|
|
|
|
)
|
|
|
|
pure AppPath {_pathIsInput = False, ..}
|