hydra-kernel-0.17.3: src/main/haskell/Hydra/Decode/Regex.hs
-- Note: this is an automatically generated file. Do not edit.
-- | Term decoders for hydra.regex
module Hydra.Decode.Regex where
import qualified Hydra.Core as Core
import qualified Hydra.Errors as Errors
import qualified Hydra.Extract.Core as ExtractCore
import qualified Hydra.Graph as Graph
import qualified Hydra.Lexical as Lexical
import qualified Hydra.Overlay.Haskell.Lib.Eithers as Eithers
import qualified Hydra.Overlay.Haskell.Lib.Maps as Maps
import qualified Hydra.Overlay.Haskell.Lib.Optionals as Optionals
import qualified Hydra.Overlay.Haskell.Lib.Strings as Strings
import qualified Hydra.Regex as Regex
import qualified Hydra.Rewriting as Rewriting
import qualified Hydra.Util as Util
import Prelude hiding (Enum, Ordering, decodeFloat, encodeFloat, fail, map, pure, sum)
import qualified Data.Scientific as Sci
-- | Decoder for hydra.regex.Alternation
alternation :: Graph.Graph -> Core.Term -> Either Errors.DecodingError [Regex.RegexSequence]
alternation = ExtractCore.decodeList regexSequence
-- | Decoder for hydra.regex.Atom
atom :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.Atom
atom cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(
Core.Name "literal",
(\input -> Eithers.map (\t -> Regex.AtomLiteral t) (Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx input)))),
(Core.Name "any", (\input -> Eithers.map (\t -> Regex.AtomAny) (ExtractCore.decodeUnit cx input))),
(Core.Name "anchorStart", (\input -> Eithers.map (\t -> Regex.AtomAnchorStart) (ExtractCore.decodeUnit cx input))),
(Core.Name "anchorEnd", (\input -> Eithers.map (\t -> Regex.AtomAnchorEnd) (ExtractCore.decodeUnit cx input))),
(Core.Name "group", (\input -> Eithers.map (\t -> Regex.AtomGroup t) (alternation cx input))),
(Core.Name "class", (\input -> Eithers.map (\t -> Regex.AtomClass t) (characterClass cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.regex.CharacterClass
characterClass :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.CharacterClass
characterClass cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "negated" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralBoolean v2 -> Right v2
_ -> Left (Errors.DecodingError "expected boolean literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_negated -> Eithers.bind (ExtractCore.requireField "items" (ExtractCore.decodeList classItem) fieldMap cx) (\field_items -> Right (Regex.CharacterClass {
Regex.characterClassNegated = field_negated,
Regex.characterClassItems = field_items}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.regex.CharacterClass")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.regex.CharacterRange
characterRange :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.CharacterRange
characterRange cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "from" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_from -> Eithers.bind (ExtractCore.requireField "to" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_to -> Right (Regex.CharacterRange {
Regex.characterRangeFrom = field_from,
Regex.characterRangeTo = field_to}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.regex.CharacterRange")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.regex.ClassItem
classItem :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.ClassItem
classItem cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(
Core.Name "character",
(\input -> Eithers.map (\t -> Regex.ClassItemCharacter t) (Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx input)))),
(Core.Name "range", (\input -> Eithers.map (\t -> Regex.ClassItemRange t) (characterRange cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.regex.Quantified
quantified :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.Quantified
quantified cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "atom" atom fieldMap cx) (\field_atom -> Eithers.bind (ExtractCore.requireField "quantifier" quantifier fieldMap cx) (\field_quantifier -> Right (Regex.Quantified {
Regex.quantifiedAtom = field_atom,
Regex.quantifiedQuantifier = field_quantifier}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.regex.Quantified")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.regex.Quantifier
quantifier :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.Quantifier
quantifier cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(Core.Name "one", (\input -> Eithers.map (\t -> Regex.QuantifierOne) (ExtractCore.decodeUnit cx input))),
(Core.Name "zeroOrOne", (\input -> Eithers.map (\t -> Regex.QuantifierZeroOrOne) (ExtractCore.decodeUnit cx input))),
(Core.Name "zeroOrMore", (\input -> Eithers.map (\t -> Regex.QuantifierZeroOrMore) (ExtractCore.decodeUnit cx input))),
(Core.Name "oneOrMore", (\input -> Eithers.map (\t -> Regex.QuantifierOneOrMore) (ExtractCore.decodeUnit cx input))),
(
Core.Name "exactly",
(\input -> Eithers.map (\t -> Regex.QuantifierExactly t) (Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx input)))),
(
Core.Name "atLeast",
(\input -> Eithers.map (\t -> Regex.QuantifierAtLeast t) (Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx input)))),
(Core.Name "range", (\input -> Eithers.map (\t -> Regex.QuantifierRange_ t) (quantifierRange cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.regex.QuantifierRange
quantifierRange :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.QuantifierRange
quantifierRange cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "min" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_min -> Eithers.bind (ExtractCore.requireField "max" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_max -> Right (Regex.QuantifierRange {
Regex.quantifierRangeMin = field_min,
Regex.quantifierRangeMax = field_max}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.regex.QuantifierRange")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.regex.Regex
regex :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Regex.Alternation
regex = alternation
-- | Decoder for hydra.regex.RegexSequence
regexSequence :: Graph.Graph -> Core.Term -> Either Errors.DecodingError [Regex.Quantified]
regexSequence = ExtractCore.decodeList quantified