mirror of
https://github.com/status-im/NimYAML.git
synced 2025-01-11 12:04:26 +00:00
Improved event output conformity
This commit is contained in:
parent
8b4f781d41
commit
9eee22bbc5
@ -1084,17 +1084,16 @@ proc anchorName*(p: YamlParser, anchor: AnchorId): string {.raises: [].} =
|
||||
if value == anchor: return representation
|
||||
return ""
|
||||
|
||||
proc renderAttrs(p: YamlParser, tag: TagId, anchor: AnchorId): string =
|
||||
proc renderAttrs(p: YamlParser, tag: TagId, anchor: AnchorId,
|
||||
isPlain: bool): string =
|
||||
result = ""
|
||||
case tag
|
||||
of yTagQuestionmark: discard
|
||||
of yTagExclamationmark: result = " !"
|
||||
of yTagExclamationmark:
|
||||
when defined(yamlScalarRepInd):
|
||||
if isPlain: result &= " <!>"
|
||||
else:
|
||||
let tagUri = p.taglib.uri(tag)
|
||||
if tagUri.startsWith(yamlTagRepositoryPrefix):
|
||||
result = " !!" & tagUri[yamlTagRepositoryPrefix.len..^1]
|
||||
else:
|
||||
result = " !<" & tagUri & ">"
|
||||
result = "<" & p.taglib.uri(tag) & ">"
|
||||
if anchor != yAnchorNone: result &= " &" & p.anchorName(anchor)
|
||||
|
||||
proc display*(p: YamlParser, event: YamlStreamEvent): string
|
||||
@ -1113,17 +1112,25 @@ proc display*(p: YamlParser, event: YamlStreamEvent): string
|
||||
of yamlEndSeq: result = "-SEQ"
|
||||
of yamlStartDoc: result = "+DOC"
|
||||
of yamlEndDoc: result = "-DOC"
|
||||
of yamlStartMap: result = "+MAP" & p.renderAttrs(event.mapTag, event.mapAnchor)
|
||||
of yamlStartSeq: result = "+SEQ" & p.renderAttrs(event.seqTag, event.seqAnchor)
|
||||
of yamlStartMap:
|
||||
result = "+MAP" & p.renderAttrs(event.mapTag, event.mapAnchor, true)
|
||||
of yamlStartSeq:
|
||||
result = "+SEQ" & p.renderAttrs(event.seqTag, event.seqAnchor, true)
|
||||
of yamlScalar:
|
||||
result = "=VAL" & p.renderAttrs(event.scalarTag, event.scalarAnchor)
|
||||
when defined(yamlScalarRepInd):
|
||||
result = "=VAL" & p.renderAttrs(event.scalarTag, event.scalarAnchor,
|
||||
event.scalarRep == srPlain)
|
||||
case event.scalarRep
|
||||
of srPlain: result &= " :"
|
||||
of srSingleQuoted: result &= " \'"
|
||||
of srDoubleQuoted: result &= " \""
|
||||
of srLiteral: result &= " |"
|
||||
of srFolded: result &= " >"
|
||||
else: result &= " :"
|
||||
else:
|
||||
let isPlain = event.scalarTag == yTagExclamationmark
|
||||
result = "=VAL" & p.renderAttrs(event.scalarTag, event.scalarAnchor,
|
||||
isPlain)
|
||||
if isPlain: result &= " :"
|
||||
else: result &= " \""
|
||||
result &= yamlTestSuiteEscape(event.scalarContent)
|
||||
of yamlAlias: result = "=ALI *" & p.anchorName(event.aliasTarget)
|
@ -250,7 +250,7 @@ proc renderAttrs(tag: TagId, anchor: AnchorId): string =
|
||||
case tag
|
||||
of yTagQuestionmark: discard
|
||||
of yTagExclamationmark: result &= " !"
|
||||
else: result &= " !<" & $tag & ">"
|
||||
else: result &= " <" & $tag & ">"
|
||||
if anchor != yAnchorNone: result &= " &" & $anchor
|
||||
|
||||
proc `$`*(event: YamlStreamEvent): string {.raises: [].} =
|
||||
|
Loading…
x
Reference in New Issue
Block a user