mirror of https://github.com/status-im/NimYAML.git
Simplified docs, fixed some links. v2.1.0
This commit is contained in:
parent
cdbf426f6b
commit
eee45683ea
|
@ -1,4 +1,4 @@
|
||||||
## 2.1.0 (upcoming)
|
## 2.1.0
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ Bugfixes:
|
||||||
* Fixed a bug that prevented the presenter from outputting compact
|
* Fixed a bug that prevented the presenter from outputting compact
|
||||||
flow mappings in cMixed mode.
|
flow mappings in cMixed mode.
|
||||||
* Fixed block scalars as mapping keys not being presented properly.
|
* Fixed block scalars as mapping keys not being presented properly.
|
||||||
|
* Added workaround for a regression bug in Nim 2.0.2
|
||||||
|
(https://github.com/nim-lang/Nim/issues/23112)
|
||||||
|
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@ API Overview
|
||||||
============
|
============
|
||||||
|
|
||||||
.. importdoc::
|
.. importdoc::
|
||||||
api/yaml/loading.nim, api/yaml/dumping.nim, api/yaml/annotations.nim,
|
api/yaml/loading.nim, api/yaml/dumping.nim, api/yaml/native.nim,
|
||||||
api/yaml/taglib.nim, api/yaml/style.nim, api/yaml/dom.nim, api/yaml/tojson.nim,
|
api/yaml/annotations.nim, api/yaml/taglib.nim, api/yaml/style.nim,
|
||||||
|
api/yaml/dom.nim, api/yaml/tojson.nim,
|
||||||
api/yaml/parser.nim, api/yaml/presenter.nim, api/yaml/data.nim,
|
api/yaml/parser.nim, api/yaml/presenter.nim, api/yaml/data.nim,
|
||||||
api/yaml/stream.nim
|
api/yaml/stream.nim
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,22 @@
|
||||||
Serialization Overview
|
Serialization Overview
|
||||||
======================
|
======================
|
||||||
|
|
||||||
|
.. importdoc::
|
||||||
|
api/yaml/loading.nim, api/yaml/dumping.nim, api/yaml/native.nim,
|
||||||
|
api/yaml/annotations.nim, api/yaml/taglib.nim, api/yaml/style.nim,
|
||||||
|
api/yaml/dom.nim, api/yaml/tojson.nim,
|
||||||
|
api/yaml/parser.nim, api/yaml/presenter.nim, api/yaml/data.nim,
|
||||||
|
api/yaml/stream.nim
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
============
|
============
|
||||||
|
|
||||||
NimYAML tries hard to make transforming YAML characters streams to native Nim
|
NimYAML tries hard to make transforming YAML characters streams to native Nim
|
||||||
types and vice versa as easy as possible. In simple scenarios, you might not
|
types and vice versa as easy as possible. In simple scenarios, you might not
|
||||||
need anything else than the two procs
|
need anything else than the two procs `dump`_ and `load`_. On the other side,
|
||||||
`dump <api/dumping.html#dump%2CDumper%2CK>`_
|
the process should be as customizable as possible to allow the user to tightly
|
||||||
and `load <api/loading.html#load%2C%2CK>`_. On the other side, the process
|
control how the generated YAML character stream will look and how a YAML
|
||||||
should be as customizable as possible to allow the user to tightly control how
|
character stream is interpreted.
|
||||||
the generated YAML character stream will look and how a YAML character stream is
|
|
||||||
interpreted.
|
|
||||||
|
|
||||||
An important thing to remember in NimYAML is that unlike in interpreted
|
An important thing to remember in NimYAML is that unlike in interpreted
|
||||||
languages like Ruby, Nim cannot load a YAML character stream without knowing the
|
languages like Ruby, Nim cannot load a YAML character stream without knowing the
|
||||||
|
@ -89,7 +94,7 @@ However, it doesn't need to. For example, if you have a YAML file like this:
|
||||||
- 1
|
- 1
|
||||||
- 2
|
- 2
|
||||||
|
|
||||||
You can simply load it into a `seq[int]`. If your YAML file contains differently
|
You can simply load it into a ``seq[int]``. If your YAML file contains differently
|
||||||
typed values in the same collection, you can use an implicit variant object, see
|
typed values in the same collection, you can use an implicit variant object, see
|
||||||
below.
|
below.
|
||||||
|
|
||||||
|
@ -247,9 +252,8 @@ These tags are generated on the fly based on the types you instantiate
|
||||||
``Table`` or ``seq`` with.
|
``Table`` or ``seq`` with.
|
||||||
|
|
||||||
You may customize the tags used for your types by using the template
|
You may customize the tags used for your types by using the template
|
||||||
`setTagUri <api/taglib.html#setTagUri.t%2Ctypedesc%2Cstring>`_. It may not
|
`setTagUri`_. It may not be applied to scalar and collection types implemented
|
||||||
be applied to scalar and collection types implemented by NimYAML, but you can
|
by NimYAML, but you can for example use it on a certain ``seq`` type:
|
||||||
for example use it on a certain ``seq`` type:
|
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
|
@ -378,22 +382,20 @@ representObject
|
||||||
proc representObject*(
|
proc representObject*(
|
||||||
ctx : var SerializationContext,
|
ctx : var SerializationContext,
|
||||||
value: MyObject,
|
value: MyObject,
|
||||||
tag : TagId,
|
tag : Tag,
|
||||||
): {.raises: [YamlSerializationError].}
|
): {.raises: [YamlSerializationError].}
|
||||||
|
|
||||||
This proc should push a list of tokens that represent the type into the
|
This proc should push a list of tokens that represent the type into the
|
||||||
serialization context via ``ctx.put``. Follow the following guidelines when
|
serialization context via ``ctx.put``. Follow the following guidelines when
|
||||||
implementing a custom ``representObject`` proc:
|
implementing a custom ``representObject`` proc:
|
||||||
|
|
||||||
- You can use the helper template
|
|
||||||
`presentTag <api/native.html#presentTag%2CSerializationContext%2Ctypedesc>`_
|
|
||||||
for outputting the tag.
|
|
||||||
- Always output the first token with a ``yAnchorNone``. Anchors will be set
|
- Always output the first token with a ``yAnchorNone``. Anchors will be set
|
||||||
automatically by ``ref`` type handling.
|
automatically by ``ref`` type handling.
|
||||||
- When outputting non-scalar types, you should use ``representChild`` for
|
- When outputting non-scalar types, you should use ``representChild`` for
|
||||||
contained values.
|
contained values.
|
||||||
- Always use the ``tag`` parameter as tag for the first token you generate.
|
- Always use the ``tag`` parameter as tag for the first token you generate.
|
||||||
- Never write a ``representObject`` proc for ``ref`` types.
|
- Never write a ``representObject`` proc for ``ref`` types, instead write the
|
||||||
|
proc for the ref'd type.
|
||||||
|
|
||||||
The following example for representing to a YAML scalar is the actual
|
The following example for representing to a YAML scalar is the actual
|
||||||
implementation of representing ``int`` types:
|
implementation of representing ``int`` types:
|
||||||
|
|
|
@ -1,4 +1,2 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
- { name: Karl Koch, age: 23 }
|
- { name: Karl Koch, age: 23 }
|
||||||
- { name: Peter Pan, age: 12 }
|
- { name: Peter Pan, age: 12 }
|
|
@ -1,6 +1,4 @@
|
||||||
%YAML 1.2
|
--- &a
|
||||||
%TAG !n! tag:nimyaml.org,2016:
|
|
||||||
--- !n!custom:NodeObj &a
|
|
||||||
name: Node 1
|
name: Node 1
|
||||||
left:
|
left:
|
||||||
name: Node 2
|
name: Node 2
|
||||||
|
|
|
@ -23,7 +23,7 @@ type
|
||||||
of ckNone:
|
of ckNone:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
setTag(Person, nimTag("demo:Person"))
|
setTag(Person, Tag("!Person"))
|
||||||
|
|
||||||
var list: seq[Container]
|
var list: seq[Container]
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
%YAML 1.2
|
|
||||||
%TAG !n! tag:nimyaml.org,2016:
|
|
||||||
---
|
|
||||||
- this is a string
|
- this is a string
|
||||||
- 42
|
- 42
|
||||||
- false
|
- false
|
||||||
- !!str 23
|
- !!str 23
|
||||||
- !n!demo:Person {name: Trillian}
|
- !Person {name: Trillian}
|
||||||
- !!null
|
- !!null
|
|
@ -2,7 +2,7 @@ import yaml, yaml/data, yaml/parser, yaml/hints, streams
|
||||||
type Person = object
|
type Person = object
|
||||||
name: string
|
name: string
|
||||||
|
|
||||||
setTag(Person, nimTag("demo:Person"), yTagPerson)
|
setTag(Person, Tag("!Person"), yTagPerson)
|
||||||
|
|
||||||
var
|
var
|
||||||
s = newFileStream("in.yaml", fmRead)
|
s = newFileStream("in.yaml", fmRead)
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
%YAML 1.2
|
|
||||||
%TAG !n! tag:nimyaml.org,2016:
|
|
||||||
--- !!seq
|
|
||||||
- this is a string
|
- this is a string
|
||||||
- 42
|
- 42
|
||||||
- false
|
- false
|
||||||
- !!str 23
|
- !!str 23
|
||||||
- !n!demo:Person {name: Trillian}
|
- !Person {name: Trillian}
|
|
@ -1,10 +1,10 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "2.0.0"
|
version = "2.1.0"
|
||||||
author = "Felix Krause"
|
author = "Felix Krause"
|
||||||
description = "YAML 1.2 implementation for Nim"
|
description = "YAML 1.2 implementation for Nim"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
skipDirs = @["bench", "doc", "server", "test", "tools"]
|
skipDirs = @[".github", "bench", "doc", "server", "test", "tools"]
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue