pi/src/Main.idr

46 lines
1.1 KiB
Idris

module Main
import Core.Check
import Core.Term
import Parser.Parse
import Data.Vect
import Data.String
import System
import System.File
unwrap : {a : Type} -> Show a => Either a b -> IO b
unwrap {a = a} = \case
Left e => do
case a of
String => putStrLn e
_ => printLn e
exitFailure
Right s => pure s
replRead : IO String
replRead = do
line <- getLine
if null (trim line)
then replRead
else case line of
":exit" => exitSuccess
_ => pure line
repl : (n : Nat) -> Vect n String -> IO ()
repl n env = do
line <- replRead
printLn =<< unwrap (parseEnv n env line)
repl n env
main : IO ()
main = getArgs >>= \case
(_ :: x :: _) => do
putStr (x ++ ": ")
res <- readFile x >>= unwrap >>= unwrap . parsetoplevel
>>= unwrap . (`typecheck` TTop)
if fst res
then putStrLn ("Success !")
else unwrap (Left res)
_ => repl 0 []