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