module Command.CStructs2MsgHandlers
( cstructs2MsgHandlers
, ErrorCode
)
where
import Data.String.Extra as S ( safeReadFile )
import Command.Result ( Result (..) )
import Data.Location ( Location (..) )
import qualified Language.C.AbsC as C ( TranslationUnit )
import qualified Language.C.ParC as C ( myLexer, pTranslationUnit )
import qualified Language.Trans.CStructs2MsgHandlers as T ( cstructs2MsgHandlers )
cstructs2MsgHandlers :: FilePath
-> IO (Result ErrorCode)
cstructs2MsgHandlers :: String -> IO (Result ErrorCode)
cstructs2MsgHandlers String
fp = do
result <- String -> IO (Either String TranslationUnit)
parseCFile String
fp
case T.cstructs2MsgHandlers =<< result of
Right String
content -> String -> IO ()
putStrLn String
content IO () -> IO (Result ErrorCode) -> IO (Result ErrorCode)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Result ErrorCode -> IO (Result ErrorCode)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Result ErrorCode
forall a. Result a
Success
Left String
msg -> Result ErrorCode -> IO (Result ErrorCode)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result ErrorCode -> IO (Result ErrorCode))
-> Result ErrorCode -> IO (Result ErrorCode)
forall a b. (a -> b) -> a -> b
$ ErrorCode -> String -> Location -> Result ErrorCode
forall a. a -> String -> Location -> Result a
Error ErrorCode
ecCStructError String
msg (String -> Location
LocationFile String
fp)
where
parseCFile :: FilePath -> IO (Either String C.TranslationUnit)
parseCFile :: String -> IO (Either String TranslationUnit)
parseCFile String
fp' = do
content <- String -> IO (Either String String)
S.safeReadFile String
fp'
return $ C.pTranslationUnit . C.myLexer =<< content
type ErrorCode = Int
ecCStructError :: ErrorCode
ecCStructError :: ErrorCode
ecCStructError = ErrorCode
1