Module yaml.taglib
-
Imports
- Types
- Vars
-
Consts
y Tag Exclamation Mark y Tag Question Mark y Tag String y Tag Sequence y Tag Mapping y Tag Null y Tag Boolean y Tag Integer y Tag Float y Tag Ordered Map y Tag Pairs y Tag Set y Tag Binary y Tag Merge y Tag Timestamp y Tag Value y Tag Yaml y Tag Nim Field y Tag Nim Nil String y Tag Nim Nil Seq y First Custom Tag Id yaml Tag Repository Prefix y Tag Nim Char y Tag Nim Int8 y Tag Nim Int16 y Tag Nim Int32 y Tag Nim Int64 y Tag Nim UInt8 y Tag Nim UInt16 y Tag Nim UInt32 y Tag Nim UInt64 y Tag Nim Float32 y Tag Nim Float64
- Procs
- Templates
The taglib API enables you to query real names of tags emitted by the parser and create own tags. It also enables you to define tags for types used with the serialization API.
Imports
Types
TagId = distinct int
-
A TagId identifies a tag URI, like for example "tag:yaml.org,2002:str". The URI corresponding to a TagId can be queried from the TagLibrary which was used to create this TagId; e.g. when you parse a YAML character stream, the TagLibrary of the parser is the one which generates the resulting TagId s.
URI strings are mapped to TagId s for efficiency reasons (you do not need to compare strings every time) and to be able to discover unknown tag URIs early in the parsing process.
Source TagLibrary = ref object tags*: Table[string, TagId] nextCustomTagId*: TagId secondaryPrefix*: string
-
A TagLibrary maps tag URIs to TagId s.
When YamlParser encounters tags not existing in the tag library, it will use registerUri to add the tag to the library.
You can base your tag library on common tag libraries by initializing them with initFailsafeTagLibrary, initCoreTagLibrary or initExtendedTagLibrary.
Source
Vars
serializationTagLibrary = initSerializationTagLibrary()
-
contains all local tags that are used for type serialization. Does not contain any of the specific default tags for sequences or maps, as those are not suited for Nim's static type system.
Should not be modified manually. Will be extended by serializable.
Source
Consts
yTagExclamationMark: TagId = 0
- ! non-specific tag Source
yTagQuestionMark: TagId = 1
- ? non-specific tag Source
yTagString: TagId = 2
- !!str tag Source
yTagSequence: TagId = 3
- !!seq tag Source
yTagMapping: TagId = 4
- !!map tag Source
yTagNull: TagId = 5
- !!null tag Source
yTagBoolean: TagId = 6
- !!bool tag Source
yTagInteger: TagId = 7
- !!int tag Source
yTagFloat: TagId = 8
- !!float tag Source
yTagOrderedMap: TagId = 9
- !!omap tag Source
yTagPairs: TagId = 10
- !!pairs tag Source
yTagSet: TagId = 11
- !!set tag Source
yTagBinary: TagId = 12
- !!binary tag Source
yTagMerge: TagId = 13
- !!merge tag Source
yTagTimestamp: TagId = 14
- !!timestamp tag Source
yTagValue: TagId = 15
- !!value tag Source
yTagYaml: TagId = 16
- !!yaml tag Source
yTagNimField: TagId = 100
- This tag is used in serialization for the name of a field of an object. It may contain any string scalar that is a valid Nim symbol. Source
yTagNimNilString: TagId = 101
- for strings that are nil Source
yTagNimNilSeq: TagId = 102
- for seqs that are nil. This tag is used regardless of the seq's generic type parameter. Source
yFirstCustomTagId: TagId = 1000
- The first TagId which should be assigned to an URI that does not exist in the YamlTagLibrary which is used for parsing. Source
yamlTagRepositoryPrefix = "tag:yaml.org,2002:"
- Source
yTagNimChar = 100
- Source
yTagNimInt8 = 101
- Source
yTagNimInt16 = 102
- Source
yTagNimInt32 = 103
- Source
yTagNimInt64 = 104
- Source
yTagNimUInt8 = 105
- Source
yTagNimUInt16 = 106
- Source
yTagNimUInt32 = 107
- Source
yTagNimUInt64 = 108
- Source
yTagNimFloat32 = 109
- Source
yTagNimFloat64 = 110
- Source
Procs
proc `==`(left, right: TagId): bool {.
borrow.}- Source
proc hash(id: TagId): Hash {.
borrow.}- Source
proc `$`(id: TagId): string {.
raises: [], tags: [].}- Source
proc initTagLibrary(): TagLibrary {.
raises: [], tags: [].}- initializes the tags table and sets nextCustomTagId to yFirstCustomTagId. Source
proc registerUri(tagLib: TagLibrary; uri: string): TagId {.
raises: [], tags: [].}- registers a custom tag URI with a TagLibrary. The URI will get the TagId nextCustomTagId, which will be incremented. Source
proc uri(tagLib: TagLibrary; id: TagId): string {.
raises: [KeyError], tags: [].}- retrieve the URI a TagId maps to. Source
proc initFailsafeTagLibrary(): TagLibrary {.
raises: [], tags: [].}-
Contains only:
- !
- ?
- !!str
- !!map
- !!seq
proc initCoreTagLibrary(): TagLibrary {.
raises: [], tags: [].}-
Contains everything in initFailsafeTagLibrary plus:
- !!null
- !!bool
- !!int
- !!float
proc initExtendedTagLibrary(): TagLibrary {.
raises: [], tags: [].}-
Contains everything from initCoreTagLibrary plus:
- !!omap
- !!pairs
- !!set
- !!binary
- !!merge
- !!timestamp
- !!value
- !!yaml
proc initSerializationTagLibrary(): TagLibrary {.
raises: [], tags: [].}- Source
proc yamlTag[](T125098: typedesc[char]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T125237: typedesc[int8]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T125437: typedesc[int16]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T125637: typedesc[int32]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T125837: typedesc[int64]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T126037: typedesc[uint8]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T126237: typedesc[uint16]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T126437: typedesc[uint32]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T126637: typedesc[uint64]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T126837: typedesc[float32]): TagId {.
inline, raises: [].}- autogenerated Source
proc yamlTag[](T127037: typedesc[float64]): TagId {.
inline, raises: [].}- autogenerated Source
Templates
template setTagUri[](t: typedesc; uri: string): typed
- Associate the given uri with a certain type. This uri is used as YAML tag when loading and dumping values of this type. Source
template setTagUri[](t: typedesc; uri: string; idName: untyped): typed
- Like setTagUri, but lets you choose a symbol for the TagId of the uri. This is only necessary if you want to implement serialization / construction yourself. Source
template markAsImplicit[](t: typedesc): typed
- Mark a variant object type as implicit. This requires the type to consist of nothing but a case expression and each branch of the case expression containing exactly one field - with the exception that one branch may contain zero fields. Source