1 {-# LANGUAGE UndecidableInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
5 import Control.Monad (Monad(..), forM_)
6 import Data.Either (Either(..))
7 import Data.Function (($))
8 import System.IO (IO, stdout, stderr, print)
9 import Text.Show (Show(..))
10 import qualified Data.Strict as S
11 import qualified System.Environment as Env
13 import qualified Language.Symantic.Document as Doc
15 import qualified Hcompta.LCC.Sym as LCC.Sym
16 import Hcompta.LCC.Read
17 import Hcompta.LCC.Write
19 import Prelude (error)
25 readLCC @LCC.Sym.SRC arg >>= \case
26 Left (Error_Read_Syntax err) ->
27 showParseError err >>=
29 Left (Error_Read_Semantic err) -> error $ show err
30 Right (r, warns) -> do
33 (`Doc.ansiIO` stdout) $
34 write (context_write, r)
37 printError :: Show err => Either err a -> IO a
38 printError (Left err) = error $ show err
39 printError (Right a) = return a
41 printErrorS :: Show err => S.Either err a -> IO a
42 printErrorS (S.Left err) = error $ show err
43 printErrorS (S.Right a) = return a
46 -- dbg :: Show a => String -> a -> a
47 -- dbg msg x = trace (msg ++ " = " ++ show x) x