shrub/pkg/hs-urbit/lib/Noun.hs

46 lines
1.1 KiB
Haskell
Raw Normal View History

module Noun
2019-07-12 04:16:40 +03:00
( module Noun.Core
, module Noun.Convert
, module Noun.Conversions
, module Noun.Atom
, module Noun.Jam
, module Noun.Cue
, module Noun.TH
, module Data.Word
2019-07-12 04:16:40 +03:00
, _Cue
2019-07-16 03:01:45 +03:00
, loadFile
2019-07-12 04:16:40 +03:00
) where
import ClassyPrelude
import Control.Lens
2019-07-12 04:16:40 +03:00
import Noun.Atom
2019-07-12 22:24:44 +03:00
import Noun.Conversions
import Noun.Convert
import Noun.Core
2019-07-12 04:16:40 +03:00
import Noun.Cue
2019-07-12 22:24:44 +03:00
import Noun.Jam
2019-07-12 04:16:40 +03:00
import Noun.TH
import Data.Word
--------------------------------------------------------------------------------
2019-07-12 04:16:40 +03:00
_Cue :: Prism' ByteString Noun
_Cue = prism' jamBS (eitherToMaybe . cueBS)
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
data LoadErr = CueErr DecodeErr
| ParseErr [Text] Text
2019-07-16 03:01:45 +03:00
deriving (Eq, Ord, Show)
loadFile :: a. FromNoun a => FilePath -> IO (Either LoadErr a)
loadFile pax = do
bs <- readFile pax
case cueBS bs of
Left e -> pure $ Left (CueErr e)
Right n -> case fromNounErr n of
Left (p,e) -> pure $ Left (ParseErr p e)
Right x -> pure $ Right x