{-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Main where import Control.Monad (Monad(..), forM_) import Data.Either (Either(..)) import Data.Function (($)) import System.IO (IO, stdout, stderr, print) import Text.Show (Show(..)) import qualified Data.Strict as S import qualified System.Environment as Env import qualified Language.Symantic.Document as Doc import qualified Hcompta.LCC.Sym as LCC.Sym import Hcompta.LCC.Read import Hcompta.LCC.Write import Prelude (error) main :: IO () main = do args <- Env.getArgs forM_ args $ \arg -> readLCC @LCC.Sym.SRC arg >>= \case Left (Error_Read_Syntax err) -> showParseError err >>= (`Doc.ansiIO` stderr) Left (Error_Read_Semantic err) -> error $ show err Right (r, warns) -> do print warns -- print r (`Doc.ansiIO` stdout) $ write (context_write, r) printError :: Show err => Either err a -> IO a printError (Left err) = error $ show err printError (Right a) = return a printErrorS :: Show err => S.Either err a -> IO a printErrorS (S.Left err) = error $ show err printErrorS (S.Right a) = return a {- -- dbg :: Show a => String -> a -> a -- dbg msg x = trace (msg ++ " = " ++ show x) x -}