| Copyright | (C) MLabs 2025 |
|---|---|
| License | Apache 2.0 |
| Maintainer | koz@mlabs.city, sean@mlabs.city |
| Safe Haskell | None |
| Language | Haskell2010 |
Covenant.JSON
Contents
Description
JSON serialization and deserialization utilities for the ASG.
Note on Sum Type Encoding:
Unless otherwise noted, a Haskell sum type like:
data Foo = Bar | Baz Int
Is encoded to JSON using {tag: <CTOR NAME>, fields: [<Arg1>, <Arg2>, <ArgN>]}
This is used for all Haskell sum types which do not have LabelOptic
instnaces. For those with field names given by such instances, the fields
part of the encoded sum is not an array of arguments, but instead a JSON
object, with fields whose names correspond to the label optics. Comments make
it clear which types are encoded in which way.
Since: 1.3.0
Synopsis
- data Version = Version {}
- data SerializeErr
- mkDatatypeInfos :: [DataDeclaration AbstractTy] -> Either String (Map TyName (DatatypeInfo AbstractTy))
- compileAndSerialize :: FilePath -> [DataDeclaration AbstractTy] -> ASGBuilder a -> Version -> ExceptT SerializeErr IO ()
- data DeserializeErr
- deserializeAndValidate :: FilePath -> ExceptT DeserializeErr IO ASG
- deserializeAndValidate_ :: FilePath -> IO ASG
Serialization
Represents a Covenant version. This is currently just a tag, but may be used in the future to enforce compatibility.
Since: 1.3.0
data SerializeErr Source #
The errors that can arise from compileAndSerialize not stemming from
IO.
Since: 1.3.0
Constructors
| DatatypeConversionFailure String | A datatype was specified in a way that isn't valid. |
| ASGCompilationFailure CovenantError | The supplied ASG failed to compile. |
Instances
| Show SerializeErr Source # | |
Defined in Covenant.JSON Methods showsPrec :: Int -> SerializeErr -> ShowS # show :: SerializeErr -> String # showList :: [SerializeErr] -> ShowS # | |
| Eq SerializeErr Source # | |
Defined in Covenant.JSON | |
mkDatatypeInfos :: [DataDeclaration AbstractTy] -> Either String (Map TyName (DatatypeInfo AbstractTy)) Source #
Given a collection of datatype declarations, convert them to
DatatypeInfos by generating their base functor and Boehm-Berrarducci
encodings. Then add to these all the base functors for the built-in types.
Since: 1.3.0
compileAndSerialize :: FilePath -> [DataDeclaration AbstractTy] -> ASGBuilder a -> Version -> ExceptT SerializeErr IO () Source #
Given a FilePath to write output to, a collection of data declarations,
an ASGBuilder and a version tag, compile the ASG, then write it to the
given file path in its JSON serialized form, together with the data types.
Since: 1.3.0
Deserialization
data DeserializeErr Source #
The errors that can arise from deserializeAndValidate not stemming from
IO.
Since: 1.3.0
Constructors
| JSONParseFailure String | The serial form's JSON was not valid. This means that the given file cannot be an ASG. |
| ASGValidationFail CovenantError | The deserialized JSON corresponds to an ASG, but not a valid one. |
Instances
| Show DeserializeErr Source # | |
Defined in Covenant.JSON Methods showsPrec :: Int -> DeserializeErr -> ShowS # show :: DeserializeErr -> String # showList :: [DeserializeErr] -> ShowS # | |
| Eq DeserializeErr Source # | |
Defined in Covenant.JSON Methods (==) :: DeserializeErr -> DeserializeErr -> Bool # (/=) :: DeserializeErr -> DeserializeErr -> Bool # | |
deserializeAndValidate :: FilePath -> ExceptT DeserializeErr IO ASG Source #
Given a FilePath to a serialized ASG, decode it if possible.
Since: 1.3.0
deserializeAndValidate_ :: FilePath -> IO ASG Source #
Like deserializeAndValidate but runs directly in IO.
Note
This is mostly designed for use in tests, as it has no ability to 'trap'
validation or deserialization errors. You most likely want
deserializeAndValidate.
Since: 1.3.0