shrub/pkg/king/lib/Noun.hs

48 lines
1.1 KiB
Haskell
Raw Normal View History

module Noun
2019-08-13 01:51:37 +03:00
( module Noun.Atom
, module Data.Word
2019-07-12 04:16:40 +03:00
, module Noun.Conversions
2019-08-13 01:51:37 +03:00
, module Noun.Convert
, module Noun.Core
2019-07-12 04:16:40 +03:00
, module Noun.Cue
2019-08-13 01:51:37 +03:00
, module Noun.Jam
, module Noun.Tank
2019-07-12 04:16:40 +03:00
, module Noun.TH
, _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-08-13 01:51:37 +03:00
import Data.Word
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-08-13 01:51:37 +03:00
import Noun.Tank
2019-07-12 04:16:40 +03:00
import Noun.TH
--------------------------------------------------------------------------------
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