26 lines
699 B
Haskell
26 lines
699 B
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Main (main) where
|
|
|
|
import Data.Text (Text)
|
|
import qualified Data.Text.IO as TIO
|
|
import Parser (Parser, parseProgram)
|
|
import System.Environment (getArgs)
|
|
import Text.Megaparsec (errorBundlePretty, parse)
|
|
|
|
printParser :: (Show s) => Parser s -> Text -> IO ()
|
|
printParser parser input = case parse parser "" input of
|
|
Left err -> putStrLn $ errorBundlePretty err
|
|
Right result -> print result
|
|
|
|
parseFile :: FilePath -> IO ()
|
|
parseFile filePath = do
|
|
input <- TIO.readFile filePath
|
|
printParser parseProgram input
|
|
|
|
main :: IO ()
|
|
main = do
|
|
args <- getArgs
|
|
case args of
|
|
[filePath] -> parseFile filePath
|
|
_ -> putStrLn "Usage: programName filePath" |