blob: 5dfb25e8c3ef997a72af69549a114adcd4c7ce73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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
|