1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-11 08:25:46 +03:00
juvix/app/GlobalOptions.hs

125 lines
3.2 KiB
Haskell
Raw Normal View History

module GlobalOptions
( module GlobalOptions,
)
where
2022-12-20 15:05:40 +03:00
import CommonOptions
import Juvix.Compiler.Abstract.Pretty.Options qualified as Abstract
import Juvix.Compiler.Internal.Pretty.Options qualified as Internal
import Juvix.Data.Error.GenericError qualified as E
import Juvix.Extra.Paths
data GlobalOptions = GlobalOptions
{ _globalNoColors :: Bool,
_globalShowNameIds :: Bool,
_globalBuildDir :: Maybe (AppPath Dir),
_globalOnlyErrors :: Bool,
_globalNoApe :: Bool,
2022-08-19 17:57:07 +03:00
_globalStdin :: Bool,
_globalNoTermination :: Bool,
_globalNoPositivity :: Bool,
2022-12-20 15:05:40 +03:00
_globalNoStdlib :: Bool
}
2022-12-20 15:05:40 +03:00
deriving stock (Eq, Show)
makeLenses ''GlobalOptions
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
project GlobalOptions {..} =
E.GenericOptions
{ E._showNameIds = _globalShowNameIds,
E._genericNoApe = _globalNoApe
}
2022-09-14 17:16:15 +03:00
defaultGlobalOptions :: GlobalOptions
defaultGlobalOptions =
GlobalOptions
{ _globalNoColors = False,
_globalShowNameIds = False,
_globalOnlyErrors = False,
_globalNoApe = False,
_globalNoTermination = False,
_globalBuildDir = Nothing,
2022-08-19 17:57:07 +03:00
_globalStdin = False,
_globalNoPositivity = False,
2022-12-20 15:05:40 +03:00
_globalNoStdlib = False
}
-- | 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
_globalNoColors <-
switch
( long "no-colors"
<> help "Disable ANSI formatting"
)
_globalShowNameIds <-
switch
( long "show-name-ids"
<> help "Show the unique number of each identifier when pretty printing"
)
_globalBuildDir <-
optional
( parseBuildDir
( long "internal-build-dir"
<> help "Directory for compiler internal output"
)
)
_globalNoApe <-
switch
( long "no-format"
<> help "Disable the new pretty printing algorithm"
)
2022-08-19 17:57:07 +03:00
_globalStdin <-
switch
( long "stdin"
<> help "Read from Stdin"
)
_globalOnlyErrors <-
switch
( long "only-errors"
<> help "Only print errors in a uniform format (used by juvix-mode)"
)
_globalNoTermination <-
switch
( long "no-termination"
<> help "Disable termination checking"
)
_globalNoPositivity <-
switch
( long "no-positivity"
<> help "Disable positivity checking for inductive types"
)
_globalNoStdlib <-
switch
( long "no-stdlib"
<> help "Do not use the standard library"
)
2022-09-14 17:16:15 +03:00
return GlobalOptions {..}
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, ..}