perga/app/Main.hs

31 lines
800 B
Haskell
Raw Normal View History

2024-10-05 13:31:09 -07:00
module Main where
2024-11-11 17:57:14 -08:00
import Check
2024-11-15 18:39:44 -08:00
import qualified Data.Text.IO as T
2024-10-06 14:02:35 -07:00
import Expr
2024-10-05 16:04:13 -07:00
import Parser
2024-11-15 18:39:44 -08:00
import Repl
import System.Environment
2024-10-05 16:04:13 -07:00
import System.IO
2024-11-11 14:34:55 -08:00
2024-10-05 13:31:09 -07:00
main :: IO ()
2024-10-05 16:04:13 -07:00
main = do
2024-11-15 18:39:44 -08:00
args <- getArgs
case args of
[] -> repl
[file] -> handleFile file
_ -> putStrLn "usage './perga' for repl and './perga <filename>' to get input from a file"
handleFile :: String -> IO ()
handleFile fileName =
do
fileH <- openFile fileName ReadMode
input <- T.hGetContents fileH
case pAll input of
Left err -> putStrLn err
Right expr -> case findType [] expr of
Left err -> print err
Right ty -> do
putStrLn $ "expr:\t" ++ prettyS expr
putStrLn $ "type:\t" ++ prettyS ty