1 {-# LANGUAGE UndecidableInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
5 import Control.Monad (Monad(..), forM_, (=<<))
7 import Data.Typeable (Typeable)
8 import Data.Either (Either(..))
9 import Data.Function (($))
10 import Data.Functor ((<$>))
11 import Data.List.NonEmpty (NonEmpty)
12 import System.IO (IO, stdout, stderr, print)
13 import Text.Show (Show(..))
14 import qualified Data.Strict as S
15 import qualified System.Environment as Env
17 import qualified Language.Symantic.Document as Doc
18 import qualified Language.Symantic as Sym
20 import qualified Hcompta.LCC.Sym as LCC.Sym
21 import Hcompta.LCC.Posting (SourcePos)
22 import Hcompta.LCC.Read
23 import Hcompta.LCC.Write
24 import Hcompta.LCC.Compta
25 import Hcompta.LCC.Source
26 import Hcompta.LCC.Sym.Compta ()
28 import Prelude (error)
36 readCompta @LCC.Sym.SRC @SS consTransactions arg >>= \case
37 Left (Error_Read_Syntax err) ->
38 showParseError err >>=
40 Left (Error_Read_Semantic err) -> error $ show err
41 Right (r, warns) -> do
44 (`Doc.ansiIO` stdout) $
45 write (context_write, r)
47 printError :: Show err => Either err a -> IO a
48 printError (Left err) = error $ show err
49 printError (Right a) = return a
51 printErrorS :: Show err => S.Either err a -> IO a
52 printErrorS (S.Left err) = error $ show err
53 printErrorS (S.Right a) = return a
59 Gram_Term src ss (P.ParsecT P.Dec Text (SS.StateT (Sym.Imports, Modules src ss) Identity)) =>
61 Either (P.ParseError Char P.Dec) (AST_Term src ss)
63 let mods::Modules src ss =
64 either (error . show) id $
65 Sym.deleteDefTermInfix ([] `Mod` "$") `fmap`
67 let imps = importModulesAs [] mods in
70 MC.evalStateStrict (imps, mods) $
73 g = unCF $ g_term <* eoi
77 ( Gram_Term src ss (P.ParsecT P.Dec Text (SS.StateT (Sym.Imports, Modules src ss) Identity))
80 , Syms ss (BetaT View)
84 , Inj_Source (TypeVT src) src
85 , Inj_Source (TypeT src '[]) src
86 , Inj_Source (KindK src) src
87 , Inj_Source (AST_Type src) src
91 Either (Error_Term src) (TermVT src ss '[])
93 let tys = inj_Name2Type (Proxy @ss) in
94 Sym.readTerm tys CtxTyZ ast
100 Syms ss (BetaT View) =>
103 evalTe (TermVT (Term q t (TeSym te))) = do
104 putStrLn $ "Type = " <> show (q #> t)
105 case proveConstraint q of
106 Nothing -> putStrLn $ "Cannot prove Constraint: " <> show q
108 Text.putStrLn $ "View = " <> view (betaT $ te CtxTeZ)
109 case proveConstraint $ Sym.tyShow t of
110 Nothing -> putStrLn $ "No Show instance for type: " <> show t
111 Just Dict -> putStrLn $ "Eval = " <> show (eval $ te CtxTeZ)
113 -- dbg :: Show a => String -> a -> a
114 -- dbg msg x = trace (msg ++ " = " ++ show x) x