From e30739fb36ded3592643fd74cfa7809427c0c334 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Sat, 18 Feb 2017 10:40:39 +0100 Subject: [PATCH] final final fixes for event rendering --- yaml/parser.nim | 11 +++++++++-- yaml/stream.nim | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/yaml/parser.nim b/yaml/parser.nim index a2887be..0604341 100644 --- a/yaml/parser.nim +++ b/yaml/parser.nim @@ -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 diff --git a/yaml/stream.nim b/yaml/stream.nim index b7da231..8ee21bf 100644 --- a/yaml/stream.nim +++ b/yaml/stream.nim @@ -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.