HsYAML-0.2.1.4: Pure Haskell YAML 1.2 processor
Copyright© Herbert Valerio Riedel 2015-2018
LicenseGPL-2.0-or-later
Safe HaskellSafe
LanguageHaskell2010

Data.YAML.Schema

Description

Predefined YAML 1.2 Schema resolvers and encoders as well as support for defining custom resolvers and encoders.

Since: 0.2.0.0

Synopsis

Schema resolvers

YAML 1.2 Schema resolvers

data SchemaResolver Source #

Definition of a YAML 1.2 Schema

A YAML schema defines how implicit tags are resolved to concrete tags and how data is represented textually in YAML.

jsonSchemaResolver :: SchemaResolver Source #

Strict JSON schema resolver as specified in YAML 1.2 / 10.2.2. Tag Resolution

Schema encoders

YAML 1.2 Schema encoders

failsafeSchemaEncoder :: SchemaEncoder Source #

"Failsafe" schema encoder as specified in YAML 1.2 / 10.1.2. Tag Resolution

Since: 0.2.0

jsonSchemaEncoder :: SchemaEncoder Source #

Strict JSON schema encoder as specified in YAML 1.2 / 10.2.2. Tag Resolution

Since: 0.2.0

coreSchemaEncoder :: SchemaEncoder Source #

Core schema encoder as specified in YAML 1.2 / 10.3.2. Tag Resolution

Since: 0.2.0

Custom Schema encoding

According to YAML 1.2 the recommended default SchemaEncoder is coreSchemaEncoder under which Scalars are encoded as follows:

  • String which are made of Plain Characters (see isPlainChar), unambiguous (see isAmbiguous) and do not contain any leading/trailing spaces are encoded as Plain Scalar.
  • Rest of the strings are encoded in DoubleQuotes
  • Booleans are encoded using encodeBool
  • Double values are encoded using encodeDouble
  • Integral values are encoded using encodeInt

setScalarStyle :: (Scalar -> Either String (Tag, ScalarStyle, Text)) -> SchemaEncoder -> SchemaEncoder Source #

Set the Scalar style in the encoded YAML. This is a function that decides for each Scalar the type of YAML string to output.

WARNING: You must ensure that special strings (like "true"/"false"/"null"/"1234") are not encoded with the Plain style, because then they will be decoded as boolean, null or numeric values. You can use isAmbiguous to detect them.

NOTE: For different SchemaResolvers, different strings are ambiguous. For example, "true" is not ambiguous for failsafeSchemaResolver.

Since: 0.2.0

isPlainChar :: Char -> Bool Source #

These are some characters which can be used in Plain Scalars safely without any quotes (see Indicator Characters).

NOTE: This does not mean that other characters (like "\n" and other special characters like "-?:,[]{}#&*!,>%@`"'") cannot be used in Plain Scalars.

Since: 0.2.0

isAmbiguous :: SchemaResolver -> Text -> Bool Source #

Returns True if the string can be decoded by the given SchemaResolver into a Scalar which is not a of type SStr.

>>> isAmbiguous coreSchemaResolver "true"
True
>>> isAmbiguous failSchemaResolver "true"
False

Since: 0.2.0

encodeDouble :: Double -> Text Source #

Encode Double

Since: 0.2.0

encodeBool :: Bool -> Text Source #

Encode Boolean

Since: 0.2.0

encodeInt :: Integer -> Text Source #

Encode Integer

Since: 0.2.0