Haskellator/app/Main.hs

29 lines
1 KiB
Haskell
Raw Permalink Normal View History

2024-11-17 14:20:29 +00:00
module Main where
import System.Environment (getArgs)
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 the input and output file names are provided
2024-11-17 14:20:29 +00:00
case args of
(inputFilePath:outputFilePath:_) -> do
contents <- catch (readFile inputFilePath) handleReadError
let output = ppShow $ Haskellator.runParser contents inputFilePath
catch (writeFile outputFilePath output) handleWriteError
putStrLn $ "Output written to " ++ outputFilePath
_ -> putStrLn "Usage: cabal run rtlil-parse -- <input-file-path> <output-file-path>"
2024-11-17 14:20:29 +00:00
-- Handle potential file reading errors
handleReadError :: IOException -> IO String
handleReadError _ = return "Error: Could not read the input file."
-- Handle potential file writing errors
handleWriteError :: IOException -> IO ()
handleWriteError _ = putStrLn "Error: Could not write to the output file."