47 lines
1.2 KiB
Haskell
47 lines
1.2 KiB
Haskell
module Main where
|
|
|
|
import qualified Compiler as C
|
|
import Control.Monad.IO.Class
|
|
import qualified Data.Map as M
|
|
import qualified Interpreter as I
|
|
import qualified Parser as P
|
|
import System.Console.Haskeline
|
|
import qualified Text.Megaparsec as MP
|
|
import Text.Pretty.Simple
|
|
|
|
ppr :: Show a => a -> IO ()
|
|
ppr =
|
|
pPrintOpt
|
|
CheckColorTty
|
|
defaultOutputOptionsDarkBg
|
|
{ outputOptionsCompactParens = True
|
|
, outputOptionsIndentAmount = 2
|
|
, outputOptionsPageWidth = 80
|
|
}
|
|
|
|
interpret :: String -> IO ()
|
|
interpret = lex
|
|
where
|
|
lex input =
|
|
case MP.parse P.lexPrlg "-" input of
|
|
Left bundle -> putStr (MP.errorBundlePretty bundle)
|
|
Right toks -> parse toks
|
|
parse toks =
|
|
case MP.parse P.parsePrlg "-" toks of
|
|
Left bundle -> putStr (MP.errorBundlePretty bundle)
|
|
Right ast -> prologize ast
|
|
prologize ast = ppr $ map (P.ast2prlg P.defaultOps) ast
|
|
|
|
main :: IO ()
|
|
main =
|
|
runInputT defaultSettings loop
|
|
where
|
|
loop :: InputT IO ()
|
|
loop = do
|
|
minput <- getInputLine "prlg> "
|
|
case minput of
|
|
Nothing -> return ()
|
|
Just input -> do
|
|
liftIO $ interpret input
|
|
loop
|