yamlet
Safe HaskellNone
LanguageGHC2021

Yamlet.Value

Contents

Description

The values of YAML documents: the content with resolved tags, without the styles, comments and positions of the syntax tree.

A Value has FromYaml and ToYaml instances, e.g. to read a document whose structure a program does not know:

>>> decodeText @Value "!point {x: 1, y: 2.5}\n"
Right (Tagged "!point" (Mapping [(String "x",Int 1),(String "y",Float (Finite 2.5))]))

An alias becomes a copy of the value that it refers to:

>>> decodeText @Value "base: &b [1, 2]\ncopy: *b\n"
Right (Mapping [(String "base",Sequence [Int 1,Int 2]),(String "copy",Sequence [Int 1,Int 2])])

A small input with many aliases can give a large value. To prevent this, the decoder limits the aliases. Each node and each character of a scalar, a tag or an anchor counts as one unit. The aliases can add 100000 units to a document. For a document with more units, they can add as many units as the document has. The documents of a stream share the limit, as if they were one document. A document beyond the limit is an error.

Synopsis

Values

data Value Source #

The value of a node.

Eq and Ord compare the entries of mappings in order, so two mappings with the same entries in a different order are not equal, unlike in YAML.

Constructors

Null 
Bool !Bool 
Int !Integer 
Float !FloatValue 
String !Text 
Sequence ![Value] 
Mapping ![(Value, Value)]

The entries of a mapping in the order of the input. The keys are unique. The encoder does not check this for a mapping that a program builds, and a mapping with two equal keys does not read back. Keys are equal as in YAML, e.g. two mappings with the same entries in a different order are equal keys.

Tagged !Text !Value

A value with a tag that is not the tag of the core schema for it, e.g. !point {x: 1}. A scalar with a tag that the schema does not know is a String inside, e.g. !secret abc.

The encoder writes the tag. Some values read back with a change:

  • A value with its own tag of the core schema reads back without Tagged, e.g. Tagged intTag (Int 1) as Int 1.
  • A value that does not fit a tag of the core schema does not read back, e.g. a String with intTag.
  • A scalar other than a String with a tag that the schema does not know reads back as a String, e.g. Tagged "!x" (Int 5) as Tagged "!x" (String "5").
  • YAML has no syntax for the empty tag or a tag of one character, e.g. x or !. The encoder drops such a tag, e.g. Tagged "" (Int 1) reads back as Int 1.
  • A node has one tag, so the encoder writes only the outermost tag that it does not drop, e.g. Tagged "!a" (Tagged "!b" (Sequence [])) reads back as Tagged "!a" (Sequence []).

Instances

Instances details
NFData Value Source # 
Instance details

Defined in Yamlet.Value

Methods

rnf :: Value -> ()

Generic Value Source # 
Instance details

Defined in Yamlet.Value

Associated Types

type Rep Value 
Instance details

Defined in Yamlet.Value

type Rep Value = D1 ('MetaData "Value" "Yamlet.Value" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) (((C1 ('MetaCons "Null" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Bool" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :+: (C1 ('MetaCons "Int" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "Float" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FloatValue)))) :+: ((C1 ('MetaCons "String" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "Sequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Value]))) :+: (C1 ('MetaCons "Mapping" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Value, Value)])) :+: C1 ('MetaCons "Tagged" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Value)))))

Methods

from :: Value -> Rep Value x

to :: Rep Value x -> Value

Show Value Source # 
Instance details

Defined in Yamlet.Value

Methods

showsPrec :: Int -> Value -> ShowS

show :: Value -> String

showList :: [Value] -> ShowS

Eq Value Source # 
Instance details

Defined in Yamlet.Value

Methods

(==) :: Value -> Value -> Bool

(/=) :: Value -> Value -> Bool

Ord Value Source # 
Instance details

Defined in Yamlet.Value

Methods

compare :: Value -> Value -> Ordering

(<) :: Value -> Value -> Bool

(<=) :: Value -> Value -> Bool

(>) :: Value -> Value -> Bool

(>=) :: Value -> Value -> Bool

max :: Value -> Value -> Value

min :: Value -> Value -> Value

FromYaml Value Source #

The value of the node, with the tags resolved and the aliases replaced.

Instance details

Defined in Yamlet.Internal.FromYaml

ToYaml Value Source # 
Instance details

Defined in Yamlet.Internal.ToYaml

type Rep Value Source # 
Instance details

Defined in Yamlet.Value

type Rep Value = D1 ('MetaData "Value" "Yamlet.Value" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) (((C1 ('MetaCons "Null" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Bool" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :+: (C1 ('MetaCons "Int" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "Float" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FloatValue)))) :+: ((C1 ('MetaCons "String" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "Sequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Value]))) :+: (C1 ('MetaCons "Mapping" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Value, Value)])) :+: C1 ('MetaCons "Tagged" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Value)))))

data FloatValue Source #

The value of a floating-point number. A finite value is exact, e.g. 0.1 is exactly one tenth.

Arithmetic on a Scientific with a huge exponent, e.g. 1e1000000000, can use all memory. Convert a value from an untrusted input with floatValueToRealFloat or with the bounded conversions of Data.Scientific.

Constructors

Finite !Scientific

A finite value other than negative zero.

The encoder writes a value whose exponent in scientific notation is beyond the range from -1000 to 1000, e.g. 1.0e+1001, but the decoder rejects it. The decoder never gives such a value, and a Double is always in the range.

NegativeZero

Negative zero, e.g. -0.0, which a Scientific cannot hold.

Infinity 
NegativeInfinity 
NaN 

Instances

Instances details
NFData FloatValue Source # 
Instance details

Defined in Yamlet.Value

Methods

rnf :: FloatValue -> ()

Generic FloatValue Source # 
Instance details

Defined in Yamlet.Value

Associated Types

type Rep FloatValue 
Instance details

Defined in Yamlet.Value

type Rep FloatValue = D1 ('MetaData "FloatValue" "Yamlet.Value" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) ((C1 ('MetaCons "Finite" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Scientific)) :+: C1 ('MetaCons "NegativeZero" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Infinity" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "NegativeInfinity" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NaN" 'PrefixI 'False) (U1 :: Type -> Type))))

Methods

from :: FloatValue -> Rep FloatValue x

to :: Rep FloatValue x -> FloatValue

Show FloatValue Source # 
Instance details

Defined in Yamlet.Value

Methods

showsPrec :: Int -> FloatValue -> ShowS

show :: FloatValue -> String

showList :: [FloatValue] -> ShowS

Eq FloatValue Source # 
Instance details

Defined in Yamlet.Value

Methods

(==) :: FloatValue -> FloatValue -> Bool

(/=) :: FloatValue -> FloatValue -> Bool

Ord FloatValue Source # 
Instance details

Defined in Yamlet.Value

type Rep FloatValue Source # 
Instance details

Defined in Yamlet.Value

type Rep FloatValue = D1 ('MetaData "FloatValue" "Yamlet.Value" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) ((C1 ('MetaCons "Finite" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Scientific)) :+: C1 ('MetaCons "NegativeZero" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Infinity" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "NegativeInfinity" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NaN" 'PrefixI 'False) (U1 :: Type -> Type))))

floatValueToRealFloat :: RealFloat a => FloatValue -> a Source #

The nearest value of a floating-point type, e.g. Double, infinite if the value is out of its range. The decimal converts to the type directly, so it is rounded once, e.g. a Float does not go by way of a Double.

>>> map (floatValueToRealFloat @Double) [Finite 0.1, Finite 1e400, NegativeZero]
[0.1,Infinity,-0.0]

realFloatToFloatValue :: RealFloat a => a -> FloatValue Source #

The value of a floating-point number, e.g. a Double. A finite number becomes the shortest decimal that reads back as the same number, e.g. 0.1.

>>> map (realFloatToFloatValue @Double) [0.1, -0, 1 / 0]
[Finite 0.1,NegativeZero,Infinity]

describe :: Value -> String Source #

The kind of a value in plain words, for error messages, e.g. "a list". The tag of Tagged does not change it.

>>> describe (Tagged "!point" (Mapping []))
"a mapping"

Tags

valueTag :: Value -> Text Source #

The tag of a value: the tag of Tagged, or else the tag of the core schema, e.g. intTag for an Int.

>>> map valueTag [Int 1, Tagged "!point" (Mapping [])]
["tag:yaml.org,2002:int","!point"]

nullTag :: Text Source #

tag:yaml.org,2002:null.

boolTag :: Text Source #

tag:yaml.org,2002:bool.

intTag :: Text Source #

tag:yaml.org,2002:int.

floatTag :: Text Source #

tag:yaml.org,2002:float.

strTag :: Text Source #

tag:yaml.org,2002:str.

seqTag :: Text Source #

tag:yaml.org,2002:seq.

mapTag :: Text Source #

tag:yaml.org,2002:map.