1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/app/Main.hs

88 lines
2.4 KiB
Haskell
Raw Normal View History

2022-01-18 14:25:42 +03:00
{-# LANGUAGE ApplicativeDo #-}
module Main (main) where
import MiniJuvix.Utils.Prelude
import qualified MiniJuvix.Syntax.Concrete.Parser as M
2022-01-18 19:29:04 +03:00
import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Ansi as M
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base as M
2022-01-18 14:25:42 +03:00
import Options.Applicative
import Options.Applicative.Help.Pretty
import MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base (Options(_optShowNameId))
2022-01-18 14:25:42 +03:00
data Command =
Scope ScopeOptions
| Parse ParseOptions
data ScopeOptions = ScopeOptions {
_scopeRootDir :: FilePath
, _scopeInputFile :: FilePath
, _scopeShowIds :: Bool
2022-01-18 14:25:42 +03:00
}
data ParseOptions = ParseOptions
parseScope :: Parser ScopeOptions
parseScope = do
_scopeRootDir <- strOption
2022-01-18 14:25:42 +03:00
(long "rootDir"
<> short 'd'
<> metavar "DIR"
<> value "."
<> showDefault
<> help "Root directory")
_scopeInputFile <- argument str
2022-01-18 14:25:42 +03:00
(metavar "MINIJUVIX_FILE"
<> help "Path to a .mjuvix file"
)
_scopeShowIds <- switch
( long "show-name-ids"
<> help "Show the unique number of each identifier"
)
2022-01-18 14:25:42 +03:00
pure ScopeOptions {..}
parseParse :: Parser ParseOptions
parseParse = pure ParseOptions
descr :: ParserInfo Command
descr = info (parseCommand <**> helper)
(fullDesc
<> progDesc "The MiniJuvix compiler."
<> headerDoc (Just $ dullblue $ bold $ underline "MiniJuvix help")
<> footerDoc (Just foot)
)
where
foot :: Doc
foot = bold "maintainers: " <> "jan@heliax.dev; jonathan@heliax.dev"
parseCommand :: Parser Command
parseCommand = subparser (
command "parse" (info (Parse <$> parseParse) (progDesc "Parse some .mjuvix files"))
<> command "scope" (info (Scope <$> parseScope) (progDesc "Parse and scope some .mjuvix files"))
)
mkPrettyOptions :: ScopeOptions -> M.Options
mkPrettyOptions ScopeOptions {..} = M.defaultOptions {
_optShowNameId = _scopeShowIds
}
2022-01-18 14:25:42 +03:00
go :: Command -> IO ()
go c = case c of
Scope opts@ScopeOptions {..} -> do
res <- M.runModuleParserIO _scopeInputFile
2022-01-18 14:25:42 +03:00
case res of
Left err -> print err
Right m -> do
print m
putStrLn "\n\n"
s <- M.scopeCheck _scopeInputFile [m]
2022-01-18 14:25:42 +03:00
case s of
Left err -> print err
Right [r] -> M.printTopModule (mkPrettyOptions opts) r
Right _ -> error "impossible"
2022-01-18 14:25:42 +03:00
Parse _ -> putStrLn "not implemented"
main :: IO ()
main = execParser descr >>= go