mirror of
https://github.com/status-im/NimYAML.git
synced 2025-02-04 07:24:37 +00:00
Object fields get the tag !nim:field. Fixes #12.
This commit is contained in:
parent
42ddfbe5c5
commit
06faf4966d
@ -252,11 +252,11 @@ Defining a custom tag uri for a type
|
||||
</td><td>
|
||||
|
||||
.. code-block:: yaml
|
||||
%YAML 1.2
|
||||
YAML 1.2
|
||||
--- !Mob
|
||||
!!str level: !nim:system:int32 42
|
||||
!!str experience: !nim:system:int32 1800
|
||||
!!str drops: !Drops [!!str Sword of Mob Slaying]
|
||||
!nim:field level: !nim:system:int32 42
|
||||
!nim:field experience: !nim:system:int32 1800
|
||||
!nim:field drops: !Drops [!!str Sword of Mob Slaying]
|
||||
|
||||
.. raw:: html
|
||||
</td></tr></tbody></table>
|
||||
|
@ -341,8 +341,9 @@ proc representObject*[O: object|tuple](value: O, ts: TagStyle,
|
||||
let childTagStyle = if ts == tsRootOnly: tsNone else: ts
|
||||
yield startMapEvent(tag, yAnchorNone)
|
||||
for name, value in fieldPairs(value):
|
||||
yield scalarEvent(name, presentTag(string, childTagStyle),
|
||||
yAnchorNone)
|
||||
yield scalarEvent(name,
|
||||
if childTagStyle == tsNone: yTagQuestionMark else:
|
||||
yTagNimField, yAnchorNone)
|
||||
var events = representChild(value, childTagStyle, c)
|
||||
while true:
|
||||
let event = events()
|
||||
|
@ -23,6 +23,7 @@ proc `$`*(id: TagId): string =
|
||||
of yTagTimestamp: "!!timestamp"
|
||||
of yTagValue: "!!value"
|
||||
of yTagYaml: "!!yaml"
|
||||
of yTagNimField: "!nim:field"
|
||||
else: "<" & $cast[int](id) & ">"
|
||||
|
||||
proc initTagLibrary*(): TagLibrary =
|
||||
@ -76,4 +77,5 @@ proc initSerializationTagLibrary(): TagLibrary =
|
||||
result.tags["tag:yaml.org,2002:float"] = yTagFloat
|
||||
result.tags["tag:yaml.org,2002:timestamp"] = yTagTimestamp
|
||||
result.tags["tag:yaml.org,2002:value"] = yTagValue
|
||||
result.tags["tag:yaml.org,2002:binary"] = yTagBinary
|
||||
result.tags["tag:yaml.org,2002:binary"] = yTagBinary
|
||||
result.tags["!nim:field"] = yTagNimField
|
4
yaml.nim
4
yaml.nim
@ -376,6 +376,10 @@ const
|
||||
yTagYaml* : TagId = 16.TagId ## \
|
||||
## `!!yaml <http://yaml.org/type/yaml.html>`_ tag
|
||||
|
||||
yTagNimField* : TagId = 100.TagId ## \
|
||||
## 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.
|
||||
|
||||
yFirstCustomTagId* : TagId = 1000.TagId ## \
|
||||
## The first ``TagId`` which should be assigned to an URI that does not
|
||||
## exist in the ``YamlTagLibrary`` which is used for parsing.
|
||||
|
Loading…
x
Reference in New Issue
Block a user