yamlet
Safe HaskellNone
LanguageGHC2021

Yamlet.Internal.Schema

Description

The core schema of YAML 1.2.2.

This module is intended for internal use only, and may change without warning in subsequent releases.

Synopsis

Documentation

resolvePlain :: Text -> Value Source #

The value of a plain scalar without a tag. Not every such scalar is a string, e.g. null, true, 12, 0x1F and 1.5e3 are not. Quoted and block scalars are always strings.

A float whose exponent in scientific notation is beyond the range from -1000 to 1000, e.g. 1e1001, 10e1000 or 1e-1001, becomes infinity or zero, as a double does. The decoders reject such a number, because its value is not exact.

>>> map resolvePlain ["", "true", "0x1F", "1.5e3", ".inf", "yes", "9.10.3"]
[Null,Bool True,Int 31,Float (Finite 1500.0),Float Infinity,String "yes",String "9.10.3"]

resolveTagged :: Text -> Text -> Maybe Value Source #

The value of a scalar with the given resolved tag, e.g. tag:yaml.org,2002:int. Return Nothing if the text is not valid for a tag of the core schema. A scalar with another tag is a string.

A float beyond the limit becomes infinity or zero, as in resolvePlain.

>>> [resolveTagged floatTag "1", resolveTagged intTag "abc", resolveTagged seqTag "x", resolveTagged "!point" "1"]
[Just (Float (Finite 1.0)),Nothing,Nothing,Just (String "1")]

resolvePlainExact :: Text -> Either Value Value Source #

The value of a plain scalar, Left if the value is not exact.

resolveTaggedExact :: Text -> Text -> Maybe (Either Value Value) Source #

The value of a scalar with a tag, Left if the value is not exact.

startsNumber :: Char -> Bool Source #

A plain scalar that starts with the character can be a number. Only such a scalar can have a value that is not exact.

isPlainString :: Text -> Bool Source #

A plain scalar with the text is a string, e.g. 9.10.3 is a string, but 9.10 and true are not. The check ignores the syntax, so e.g. a: b passes. For both checks, use isPlainSafe.

>>> map isPlainString ["9.10.3", "9.10", "true", "a: b"]
[True,False,False,True]

isPlainSafe :: Text -> Bool Source #

The string reads back as the same string if it is a plain scalar in the block style, as a value or as a key. A key without ? must also have at most 1024 characters, which the check does not count. In a flow collection the characters ,[]{} need quotes too, so the check does not apply there.

>>> map isPlainSafe ["a:b", "a: b", "- a", "a #b", "9.10"]
[True,False,False,False,False]

isPlainPortable :: Text -> Bool Source #

As isPlainSafe, and common YAML 1.1 parsers also read the plain scalar as a string, e.g. not yes as a boolean or 12:30 as a number. The encoder writes a string without quotes only if it passes this check.

>>> map isPlainPortable ["a:b", "yes", "12:30", "2024-01-01", "9.10.3"]
[True,False,False,False,True]

isYaml11Bool :: Text -> Bool Source #

A word that YAML 1.1 reads as a boolean, but YAML 1.2 as a string, e.g. yes or off.

isYaml11NonString :: Text -> Bool Source #

A common YAML 1.1 parser reads a plain scalar with the text as a value that is not a string, e.g. the boolean yes, the base-60 number 12:30 or the date 2024-01-01. The patterns cover what PyYAML, Ruby's Psych and go-yaml v2, which Kubernetes uses, accept. The YAML 1.1 types themselves are not enough: the parsers accept more, e.g. 1,000 in Psych and 0X1F in go-yaml v2, and the type of floats accepts too much, e.g. 1.2.3.

isYaml11Timestamp :: Text -> Bool Source #

A common YAML 1.1 parser reads a plain scalar with the text as a timestamp and can build it. PyYAML has the years from 1 to 9999 of Python, and it rejects the hour 24, a leap second and a time zone of 24 hours. Psych reads the hour 24 and a leap second as a later time.

>>> map isYaml11Timestamp ["2024-01-01", "2024-01-01T12:30:00Z", "0000-01-01", "2016-12-31T23:59:60Z", "12:30"]
[True,True,False,False,False]

exponentOutOfRange :: String Source #

The error for a number beyond maxExponent.