Haskellator/app/Main.hs
Yehowshua Immanuel e295647bbe 🎵greater things are yet to come🎵
2024-12-10 20:20:29 -05:00

27 lines
766 B
Haskell

module Main where
import System.Environment (getArgs)
import System.IO
import Control.Exception (catch, IOException)
import Text.Show.Pretty (ppShow)
import Haskellator
main :: IO ()
main = do
-- Get the command-line arguments
args <- getArgs
-- Check if a file name is provided
case args of
(filePath:_) -> do
-- Attempt to read the file
contents <- catch (readFile filePath) handleReadError
putStrLn $ ppShow $ Haskellator.runParser contents filePath
[] -> putStrLn "cabal run Haskellator -- <file-path>"
-- putStrLn $ ppShow Haskellator.val
-- Handle potential file reading errors
handleReadError :: IOException -> IO String
handleReadError _ = return "Error: Could not read the file."