-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | YAML parsing combinators for improved validation and error reporting -- -- YAML parsing combinators for improved validation and error reporting @package yaml-combinators @version 1.0 -- | Combinators for parsing YAML into Haskell types. -- -- Based on the article Better Yaml Parsing. module Data.Yaml.Combinators -- | A top-level YAML parser. -- --
-- >>> parse string "howdy" -- Right "howdy" --string :: Parser Text -- | Match a specific YAML string, usually a «tag» identifying a particular -- form of an array or object. -- --
-- >>> parse (theString "hello") "hello" -- Right () -- -- >>> either putStr print $ parse (theString "hello") "bye" -- Expected "hello" instead of: -- -- bye --theString :: Text -> Parser () -- | Match a real number. -- --
-- >>> parse number "3.14159" -- Right 3.14159 --number :: Parser Scientific -- | Match an integer. -- --
-- >>> parse (integer @Int) "2017" -- Right 2017 --integer :: (Integral i, Bounded i) => Parser i -- | Match a boolean. -- --
-- >>> parse bool "yes" -- Right True --bool :: Parser Bool -- | Match an array of elements, where each of elements are matched by the -- same parser. This is the function you'll use most of the time when -- parsing arrays, as they are usually homogeneous. -- --
-- >>> parse (array string) "[a,b,c]" -- Right ["a","b","c"] --array :: Parser a -> Parser (Vector a) -- | Match an array consisting of a fixed number of elements. The way each -- element is parsed depends on its position within the array and is -- determined by the ElementParser. -- --
-- >>> parse (theArray $ (,) <$> element string <*> element bool) "[f, true]"
-- Right ("f",True)
--
theArray :: ElementParser a -> Parser a
-- | An ElementParser describes how to parse a fixed-size array
-- where each positional element has its own parser.
--
-- This can be used to parse heterogeneous tuples represented as YAML
-- arrays.
--
--
-- >>> let p = object $ (,) <$> field "name" string <*> optField "age" (integer @Int)
--
-- >>> parse p "{ name: Anton, age: 2 }"
-- Right ("Anton",Just 2)
--
-- >>> parse p "name: Roma"
-- Right ("Roma",Nothing)
--
object :: FieldParser a -> Parser a
-- | A FieldParser describes how to parse an object.
--
--
-- >>> :{
-- let p = object (Right <$ theField "type" "number" <*> field "value" number)
-- <> object (Left <$ theField "type" "string" <*> field "value" string)
--
-- >>> :}
--
--
--
-- >>> parse p "{type: string, value: abc}"
-- Right (Left "abc")
--
-- >>> parse p "{type: number, value: 123}"
-- Right (Right 123.0)
--
theField :: Text -> Text -> FieldParser ()
-- | A parse error. Reason describes the error. The Int field
-- denotes at which level the error occurred and is used to select the
-- deepest (most relevant) error when merging multiple parsers.
data ParseError
ParseError :: !Int -> Reason -> ParseError
-- | Describes what exactly went wrong during parsing.
data Reason
UnexpectedAsPartOf :: Value -> Value -> Reason
ExpectedAsPartOf :: String -> Value -> Reason
ExpectedInsteadOf :: String -> Value -> Reason
instance GHC.Base.Applicative Data.Yaml.Combinators.FieldParser
instance GHC.Base.Functor Data.Yaml.Combinators.FieldParser
instance GHC.Base.Applicative Data.Yaml.Combinators.ElementParser
instance GHC.Base.Functor Data.Yaml.Combinators.ElementParser
instance GHC.Show.Show Data.Yaml.Combinators.ParseError
instance GHC.Classes.Eq Data.Yaml.Combinators.ParseError
instance GHC.Show.Show Data.Yaml.Combinators.Reason
instance GHC.Classes.Eq Data.Yaml.Combinators.Reason
instance Generics.SOP.Universe.Generic Data.Aeson.Types.Internal.Value
instance Generics.SOP.Universe.HasDatatypeInfo Data.Aeson.Types.Internal.Value
instance GHC.Base.Functor Data.Yaml.Combinators.Parser
instance GHC.Base.Monoid (Data.Yaml.Combinators.ParserComponent a fs)
instance GHC.Base.Monoid (Data.Yaml.Combinators.Parser a)