final final fixes for event rendering

This commit is contained in:
Felix Krause 2017-02-18 10:40:39 +01:00
parent d6ace28775
commit e30739fb36
2 changed files with 14 additions and 4 deletions

View File

@ -446,8 +446,10 @@ proc endLevel(c: ParserContext, e: var YamlStreamEvent):
result = lerAdditionalMapEnd
of fplUnknown: e = emptyScalar(c)
of fplDocument:
when defined(yamlScalarRepInd): e = endDocEvent(c.lex.cur == ltDocumentEnd)
when defined(yamlScalarRepInd):
e = endDocEvent(c.lex.cur == ltDocumentEnd)
else: e = endDocEvent()
if c.lex.cur == ltDocumentEnd: c.advance()
of fplSinglePairKey:
internalError("Unexpected level kind: " & $c.level.kind)
@ -584,7 +586,6 @@ parserState blockObjectStart:
c.closeEverything()
stored = startDoc
of ltDocumentEnd:
c.advance()
c.closeEverything()
stored = afterDocument
of ltMapKeyInd:
@ -901,6 +902,12 @@ parserState flow:
if c.handleFlowItemStart(e): return true
if c.tag == yTagQuestionMark: c.tag = yTagExclamationMark
c.currentScalar(e)
when defined(yamlScalarRepInd):
case c.lex.scalarKind
of skSingleQuoted: e.scalarRep = srSingleQuoted
of skDoubleQuoted: e.scalarRep = srDoubleQuoted
of skLiteral: e.scalarRep = srLiteral
of skFolded: e.scalarRep = srFolded
result = true
state = objectEnd
stored = flowAfterObject

View File

@ -257,8 +257,11 @@ proc renderAttrs(tag: TagId, anchor: AnchorId): string =
if anchor != yAnchorNone: result &= " &" & $anchor
case tag
of yTagQuestionmark: discard
of yTagExclamationmark: result &= " !"
else: result &= " <" & $tag & ">"
of yTagExclamationmark:
when defined(yamlScalarRepInd):
if isPlain: result &= " <!>"
else:
result &= " <" & $tag & ">"
proc `$`*(event: YamlStreamEvent): string {.raises: [].} =
## outputs a human-readable string describing the given event.