Fork me on GitHub
NimYAML Home Testing Ground Docs: Overview Serialization Modules

yaml/data

    Dark Mode
Search:
Group by:

Imports

escaping

Types

Anchor = distinct string

An Anchor identifies an anchor in the current document. It is not necessarily unique and references to an anchor must be resolved immediately on occurrence.

Anchor provides the operator $ for converting to string, == for comparison, and hash for usage in a hashmap.

CollectionStyle = enum
  csAny, csBlock, csFlow, csPair
Event = object
  startPos*, endPos*: Mark
  case kind*: EventKind
  of yamlStartStream, yamlEndStream:
    nil
  of yamlStartMap:
      mapProperties*: Properties
      mapStyle*: CollectionStyle

  of yamlStartSeq:
      seqProperties*: Properties
      seqStyle*: CollectionStyle

  of yamlScalar:
      scalarProperties*: Properties
      scalarStyle*: ScalarStyle
      scalarContent*: string

  of yamlStartDoc:
      explicitDirectivesEnd*: bool
      version*: string
      handles*: seq[tuple[handle, uriPrefix: string]]

  of yamlEndDoc:
      explicitDocumentEnd*: bool

  of yamlEndMap, yamlEndSeq:
    nil
  of yamlAlias:
      aliasTarget*: Anchor

  

An element from a YamlStream. Events that start an object (yamlStartMap, yamlStartSeq, yamlScalar) have an optional anchor and a tag associated with them. The anchor will be set to yAnchorNone if it doesn't exist.

A missing tag in the YAML character stream generates the non-specific tags ? or ! according to the YAML specification. These are by convention mapped to the TagId s yTagQuestionMark and yTagExclamationMark respectively. Mapping is done by a TagLibrary.

startPos and endPos are only relevant for events from an input stream - they are generally ignored if used with events that generate output.

EventKind = enum
  yamlStartStream, yamlEndStream, yamlStartDoc, yamlEndDoc, yamlStartMap,
  yamlEndMap, yamlStartSeq, yamlEndSeq, yamlScalar, yamlAlias
Kinds of YAML events that may occur in an YamlStream. Event kinds are discussed in YamlStreamEvent.
Mark = tuple[line, column: Positive]
Properties = tuple[anchor: Anchor, tag: Tag]
ScalarStyle = enum
  ssAny, ssPlain, ssSingleQuoted, ssDoubleQuoted, ssLiteral, ssFolded
Original style of the scalar (for input), or desired style of the scalar (for output).
Tag = distinct string
A Tag contains an URI, like for example "tag:yaml.org,2002:str".

Consts

nimyamlTagRepositoryPrefix = "tag:nimyaml.org,2016:"
yamlTagRepositoryPrefix = "tag:yaml.org,2002:"
yAnchorNone: Anchor = ""
yielded when no anchor was defined for a YAML node
yTagBinary = "tag:yaml.org,2002:binary"
yTagBoolean = "tag:yaml.org,2002:bool"
yTagExclamationMark: Tag = "!"
yTagFloat = "tag:yaml.org,2002:float"
yTagInteger = "tag:yaml.org,2002:int"
yTagMapping = "tag:yaml.org,2002:map"
yTagMerge = "tag:yaml.org,2002:merge"
yTagNimField = "tag:nimyaml.org,2016:field"
yTagNull = "tag:yaml.org,2002:null"
yTagOrderedMap = "tag:yaml.org,2002:omap"
yTagPairs = "tag:yaml.org,2002:pairs"
yTagQuestionMark: Tag = "?"
yTagSequence = "tag:yaml.org,2002:seq"
yTagSet = "tag:yaml.org,2002:set"
yTagString = "tag:yaml.org,2002:str"
yTagTimestamp = "tag:yaml.org,2002:timestamp"
yTagValue = "tag:yaml.org,2002:value"
yTagYaml = "tag:yaml.org,2002:yaml"

Procs

proc `$`(event: Event): string {....raises: [], tags: [].}
outputs a human-readable string describing the given event. This string is compatible to the format used in the yaml test suite.
proc `$`(id: Anchor): string {.borrow, ...raises: [], tags: [].}
proc `$`(tag: Tag): string {.borrow, ...raises: [], tags: [].}
proc `==`(left, right: Anchor): bool {.borrow, ...raises: [], tags: [].}
proc `==`(left, right: Tag): bool {.borrow, ...raises: [], tags: [].}
proc `==`(left: Event; right: Event): bool {....raises: [], tags: [].}
compares all existing fields of the given items
proc aliasEvent(target: Anchor; startPos, endPos: Mark = defaultMark): Event {.
    inline, ...raises: [], tags: [].}
creates a new event that represents a YAML alias
proc collectionStyle(event: Event): CollectionStyle {....raises: [], tags: [].}
returns the style of the given collection start event
proc defineCoreTag(name: string): Tag {....raises: [], tags: [].}
defines a tag in YAML's core namespace, tag:yaml.org,2002:
proc defineTag(uri: string): Tag {....raises: [], tags: [].}
defines a tag. Use this to optimize away copies of globally defined Tags.
proc endDocEvent(explicit: bool = false; startPos, endPos: Mark = defaultMark): Event {.
    inline, ...raises: [], tags: [].}
creates a new event that marks the end of a YAML document
proc endMapEvent(startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
creates a new event that marks the end of a YAML mapping
proc endSeqEvent(startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
creates a new event that marks the end of a YAML sequence
proc endStreamEvent(): Event {....raises: [], tags: [].}
proc hash(id: Anchor): Hash {.borrow, ...raises: [], tags: [].}
proc hash(tag: Tag): Hash {.borrow, ...raises: [], tags: [].}
proc properties(event: Event): Properties {....raises: [], tags: [].}
returns the tag of the given event
proc renderAttrs(props: Properties; isPlain: bool = true): string {....raises: [],
    tags: [].}
proc scalarEvent(content: string = ""; tag: Tag = yTagQuestionMark;
                 anchor: Anchor = yAnchorNone; style: ScalarStyle = ssAny;
                 startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
proc scalarEvent(content: string; props: Properties; style: ScalarStyle = ssAny;
                 startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
creates a new event that represents a YAML scalar
proc startDocEvent(explicit: bool = false; version: string = "";
                   handles: seq[tuple[handle, uriPrefix: string]] = @[];
                   startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
creates a new event that marks the start of a YAML document
proc startMapEvent(style: CollectionStyle = csAny; tag: Tag = yTagQuestionMark;
                   anchor: Anchor = yAnchorNone;
                   startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
proc startMapEvent(style: CollectionStyle; props: Properties;
                   startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
creates a new event that marks the start of a YAML mapping
proc startSeqEvent(style: CollectionStyle = csAny; tag: Tag = yTagQuestionMark;
                   anchor: Anchor = yAnchorNone;
                   startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
proc startSeqEvent(style: CollectionStyle; props: Properties;
                   startPos, endPos: Mark = defaultMark): Event {.inline,
    ...raises: [], tags: [].}
creates a new event that marks the beginning of a YAML sequence
proc startStreamEvent(): Event {....raises: [], tags: [].}