hydra-kernel-0.18.0: src/main/haskell/Hydra/Core/Decode/Diff.hs
-- Note: this is an automatically generated file. Do not edit.
-- | Term decoders for hydra.core.diff
module Hydra.Core.Decode.Diff where
import qualified Hydra.Core.Decode.Model as DecodeModel
import qualified Hydra.Core.Diff as Diff
import qualified Hydra.Core.Errors as Errors
import qualified Hydra.Core.Extract.Model as ExtractModel
import qualified Hydra.Core.Graph as Graph
import qualified Hydra.Core.Lexical as Lexical
import qualified Hydra.Core.Overlay.Haskell.Lib.Eithers as Eithers
import qualified Hydra.Core.Overlay.Haskell.Lib.Maps as Maps
import qualified Hydra.Core.Overlay.Haskell.Lib.Optionals as Optionals
import qualified Hydra.Core.Overlay.Haskell.Lib.Strings as Strings
import qualified Hydra.Core.Model as Model
import qualified Hydra.Core.Rewriting as Rewriting
import qualified Hydra.Core.Util as Util
import Prelude hiding (Enum, Ordering, decodeFloat, encodeFloat, fail, lines, map, pure, sum, unlines)
import qualified Data.Scientific as Sci
import Data.Void
-- | Decoder for hydra.core.diff.Edit
edit :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError a) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.Edit a s)
edit a s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermInject v0 ->
let field = Model.injectionField v0
fname = Model.fieldName field
fterm = Model.fieldTerm field
variantMap =
Maps.fromList [
(Model.Name "retain", (\input -> Eithers.map (\t -> Diff.EditRetain) (ExtractModel.decodeUnit cx input))),
(Model.Name "set", (\input -> Eithers.map (\t -> Diff.EditSet t) (a cx input))),
(Model.Name "delete", (\input -> Eithers.map (\t -> Diff.EditDelete) (ExtractModel.decodeUnit cx input))),
(
Model.Name "descend",
(\input -> Eithers.map (\t -> Diff.EditDescend t) (ExtractModel.decodeList (stepEdit a s) cx input)))]
in (Optionals.match (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
"no such field ",
(Model.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.Hole
hole :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError t) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.Hole t s)
hole t s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermRecord v0 ->
let fieldMap = ExtractModel.toFieldMap v0
in (Eithers.bind (ExtractModel.requireField "path" (ExtractModel.decodeList s) fieldMap cx) (\field_path -> Eithers.bind (ExtractModel.requireField "type" t fieldMap cx) (\field_type -> Right (Diff.Hole {
Diff.holePath = field_path,
Diff.holeType = field_type}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.core.diff.Hole")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.HoleFiller
holeFiller :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError v) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.HoleFiller v s)
holeFiller v s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermRecord v0 ->
let fieldMap = ExtractModel.toFieldMap v0
in (Eithers.bind (ExtractModel.requireField "path" (ExtractModel.decodeList s) fieldMap cx) (\field_path -> Eithers.bind (ExtractModel.requireField "value" v fieldMap cx) (\field_value -> Right (Diff.HoleFiller {
Diff.holeFillerPath = field_path,
Diff.holeFillerValue = field_value}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.core.diff.HoleFiller")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.InvalidFillError
invalidFillError :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError t) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError v) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.InvalidFillError t v s)
invalidFillError t v s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermInject v0 ->
let field = Model.injectionField v0
fname = Model.fieldName field
fterm = Model.fieldTerm field
variantMap =
Maps.fromList [
(Model.Name "illTyped", (\input -> Eithers.map (\t2 -> Diff.InvalidFillErrorIllTyped t2) (hole t s cx input))),
(Model.Name "missingFill", (\input -> Eithers.map (\t2 -> Diff.InvalidFillErrorMissingFill t2) (hole t s cx input))),
(
Model.Name "extraFill",
(\input -> Eithers.map (\t2 -> Diff.InvalidFillErrorExtraFill t2) (Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Model.TermLiteral v1 -> case v1 of
Model.LiteralInteger v2 -> case v2 of
Model.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractModel.stripWithDecodingError cx input))))]
in (Optionals.match (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
"no such field ",
(Model.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.MigrationError
migrationError :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError t) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError v) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.MigrationError t v s)
migrationError t v s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermInject v0 ->
let field = Model.injectionField v0
fname = Model.fieldName field
fterm = Model.fieldTerm field
variantMap =
Maps.fromList [
(Model.Name "notAnInstance", (\input -> Eithers.map (\t2 -> Diff.MigrationErrorNotAnInstance t2) (v cx input))),
(Model.Name "outOfRange", (\input -> Eithers.map (\t2 -> Diff.MigrationErrorOutOfRange t2) (v cx input))),
(Model.Name "rejectedVariant", (\input -> Eithers.map (\t2 -> Diff.MigrationErrorRejectedVariant t2) (v cx input))),
(
Model.Name "illTypedResult",
(\input -> Eithers.map (\t2 -> Diff.MigrationErrorIllTypedResult t2) (mistyped t v cx input))),
(Model.Name "unfilledHole", (\input -> Eithers.map (\t2 -> Diff.MigrationErrorUnfilledHole t2) (hole t s cx input)))]
in (Optionals.match (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
"no such field ",
(Model.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.MigrationPlan
migrationPlan :: Ord n => ((Graph.Graph -> Model.Term -> Either Errors.DecodingError n) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError t) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.MigrationPlan n t s))
migrationPlan n t s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermRecord v0 ->
let fieldMap = ExtractModel.toFieldMap v0
in (Eithers.bind (ExtractModel.requireField "edits" (ExtractModel.decodeMap n (edit t s)) fieldMap cx) (\field_edits -> Eithers.bind (ExtractModel.requireField "holes" (ExtractModel.decodeList (schemaHole n t s)) fieldMap cx) (\field_holes -> Right (Diff.MigrationPlan {
Diff.migrationPlanEdits = field_edits,
Diff.migrationPlanHoles = field_holes}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.core.diff.MigrationPlan")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.Mistyped
mistyped :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError t) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.Mistyped t v)
mistyped t v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermRecord v0 ->
let fieldMap = ExtractModel.toFieldMap v0
in (Eithers.bind (ExtractModel.requireField "value" v fieldMap cx) (\field_value -> Eithers.bind (ExtractModel.requireField "type" t fieldMap cx) (\field_type -> Right (Diff.Mistyped {
Diff.mistypedValue = field_value,
Diff.mistypedType = field_type}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.core.diff.Mistyped")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.SchemaHole
schemaHole :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError n) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError t) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.SchemaHole n t s)
schemaHole n t s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermRecord v0 ->
let fieldMap = ExtractModel.toFieldMap v0
in (Eithers.bind (ExtractModel.requireField "typeName" n fieldMap cx) (\field_typeName -> Eithers.bind (ExtractModel.requireField "hole" (hole t s) fieldMap cx) (\field_hole -> Right (Diff.SchemaHole {
Diff.schemaHoleTypeName = field_typeName,
Diff.schemaHoleHole = field_hole}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.core.diff.SchemaHole")) (ExtractModel.stripWithDecodingError cx raw)
-- | Decoder for hydra.core.diff.StepEdit
stepEdit :: (Graph.Graph -> Model.Term -> Either Errors.DecodingError a) -> (Graph.Graph -> Model.Term -> Either Errors.DecodingError s) -> Graph.Graph -> Model.Term -> Either Errors.DecodingError (Diff.StepEdit a s)
stepEdit a s cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Model.TermRecord v0 ->
let fieldMap = ExtractModel.toFieldMap v0
in (Eithers.bind (ExtractModel.requireField "step" s fieldMap cx) (\field_step -> Eithers.bind (ExtractModel.requireField "edit" (edit a s) fieldMap cx) (\field_edit -> Right (Diff.StepEdit {
Diff.stepEditStep = field_step,
Diff.stepEditEdit = field_edit}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.core.diff.StepEdit")) (ExtractModel.stripWithDecodingError cx raw)