2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
|
|
|
Noun Library
|
|
|
|
|
|
|
|
This module just re-exports things from submodules.
|
|
|
|
-}
|
2020-01-24 08:28:38 +03:00
|
|
|
module Urbit.Noun
|
2020-01-23 12:22:30 +03:00
|
|
|
( module Urbit.Atom
|
2019-08-13 01:51:37 +03:00
|
|
|
, module Data.Word
|
2020-01-24 08:28:38 +03:00
|
|
|
, module Urbit.Noun.Conversions
|
|
|
|
, module Urbit.Noun.Convert
|
|
|
|
, module Urbit.Noun.Core
|
|
|
|
, module Urbit.Noun.Cue
|
|
|
|
, module Urbit.Noun.Jam
|
|
|
|
, module Urbit.Noun.Tank
|
|
|
|
, module Urbit.Noun.TH
|
|
|
|
, module Urbit.Noun.Tree
|
2019-07-12 04:16:40 +03:00
|
|
|
, _Cue
|
2019-08-22 02:49:08 +03:00
|
|
|
, LoadErr(..)
|
2019-07-16 03:01:45 +03:00
|
|
|
, loadFile
|
2019-07-12 04:16:40 +03:00
|
|
|
) where
|
|
|
|
|
|
|
|
import ClassyPrelude
|
2019-07-12 00:41:09 +03:00
|
|
|
import Control.Lens
|
2019-05-15 01:13:18 +03:00
|
|
|
|
2019-08-13 01:51:37 +03:00
|
|
|
import Data.Word
|
2020-01-23 12:22:30 +03:00
|
|
|
import Urbit.Atom
|
2020-01-24 08:28:38 +03:00
|
|
|
import Urbit.Noun.Conversions
|
|
|
|
import Urbit.Noun.Convert
|
|
|
|
import Urbit.Noun.Core
|
|
|
|
import Urbit.Noun.Cue
|
|
|
|
import Urbit.Noun.Jam
|
|
|
|
import Urbit.Noun.Tank
|
|
|
|
import Urbit.Noun.TH
|
|
|
|
import Urbit.Noun.Tree
|
2019-05-15 01:13:18 +03:00
|
|
|
|
2019-07-12 00:41:09 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2019-07-12 04:16:40 +03:00
|
|
|
_Cue :: Prism' ByteString Noun
|
|
|
|
_Cue = prism' jamBS (eitherToMaybe . cueBS)
|
2019-07-12 00:41:09 +03:00
|
|
|
where
|
2019-07-12 04:16:40 +03:00
|
|
|
eitherToMaybe (Left _) = Nothing
|
|
|
|
eitherToMaybe (Right x) = Just x
|
2019-07-16 03:01:45 +03:00
|
|
|
|
2019-08-22 02:49:08 +03:00
|
|
|
data LoadErr
|
|
|
|
= FileErr IOException
|
|
|
|
| CueErr DecodeErr
|
|
|
|
| ParseErr [Text] Text
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
instance Exception LoadErr
|
2019-07-16 03:01:45 +03:00
|
|
|
|
2020-09-25 02:43:03 +03:00
|
|
|
loadFile :: forall a. FromNoun a => FilePath -> IO (Either LoadErr a)
|
2019-08-22 02:49:08 +03:00
|
|
|
loadFile pax = try $ do
|
|
|
|
byt <- try (readFile pax) >>= either (throwIO . FileErr) pure
|
|
|
|
non <- cueBS byt & either (throwIO . CueErr) pure
|
|
|
|
res <- fromNounErr non & either (throwIO . uncurry ParseErr) pure
|
|
|
|
pure res
|