]> Git — Sourcephile - comptalang.git/blob - lcc/exe/load/Main.hs
Working REPL, with IO support.
[comptalang.git] / lcc / exe / load / Main.hs
1 {-# LANGUAGE UndecidableInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 module Main where
4
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
12
13 import qualified Language.Symantic.Document as Doc
14
15 import qualified Hcompta.LCC.Sym as LCC.Sym
16 import Hcompta.LCC.Read
17 import Hcompta.LCC.Write
18
19 import Prelude (error)
20
21 main :: IO ()
22 main = do
23 args <- Env.getArgs
24 forM_ args $ \arg ->
25 readLCC @LCC.Sym.SRC arg >>= \case
26 Left (Error_Read_Syntax err) ->
27 showParseError err >>=
28 (`Doc.ansiIO` stderr)
29 Left (Error_Read_Semantic err) -> error $ show err
30 Right (r, warns) -> do
31 print warns
32 -- print r
33 (`Doc.ansiIO` stdout) $
34 write (context_write, r)
35
36
37 printError :: Show err => Either err a -> IO a
38 printError (Left err) = error $ show err
39 printError (Right a) = return a
40
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
44
45 {-
46 -- dbg :: Show a => String -> a -> a
47 -- dbg msg x = trace (msg ++ " = " ++ show x) x
48 -}