2024-11-17 14:20:29 +00:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
import System.IO
|
|
|
|
import Control.Exception (catch, IOException)
|
2024-12-06 19:57:32 +00:00
|
|
|
import Text.Show.Pretty (ppShow)
|
2024-11-17 14:20:29 +00:00
|
|
|
|
2024-11-23 00:06:15 +00:00
|
|
|
import Haskellator
|
2024-11-17 14:20:29 +00:00
|
|
|
|
|
|
|
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 "File Contents:"
|
2024-12-10 03:51:27 +00:00
|
|
|
putStrLn $ ppShow $ Haskellator.runParser contents
|
2024-11-17 14:20:29 +00:00
|
|
|
[] -> putStrLn "cabal run Haskellator -- <file-path>"
|
2024-12-10 03:51:27 +00:00
|
|
|
-- putStrLn $ ppShow Haskellator.val
|
2024-11-17 14:20:29 +00:00
|
|
|
|
|
|
|
-- Handle potential file reading errors
|
|
|
|
handleReadError :: IOException -> IO String
|
|
|
|
handleReadError _ = return "Error: Could not read the file."
|