Haskellator/app/Main.hs

28 lines
799 B
Haskell
Raw Normal View History

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
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-09 18:20:21 +00:00
putStrLn $ Haskellator.preProcessDiscardComments contents
2024-11-17 14:20:29 +00:00
[] -> putStrLn "cabal run Haskellator -- <file-path>"
2024-12-06 19:57:32 +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."