From 936df70daa1d0987f988094aadffb81fba24d2e1 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Tue, 10 Jan 2017 11:45:55 +0100 Subject: [PATCH] Correctly present empty collections in block-only. * Fixes #33 --- yaml/presenter.nim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/yaml/presenter.nim b/yaml/presenter.nim index ad59f59..80879da 100644 --- a/yaml/presenter.nim +++ b/yaml/presenter.nim @@ -554,7 +554,11 @@ proc doPresent(s: var YamlStream, target: PresenterTarget, "Cannot have sequence as map key in JSON output!") nextState = dFlowSequenceStart of psMinimal, psCanonical: nextState = dFlowSequenceStart - of psBlockOnly: nextState = dBlockSequenceItem + of psBlockOnly: + yAssert(not s.finished()) + let next = s.peek() + if next.kind == yamlEndSeq: nextState = dFlowSequenceStart + else: nextState = dBlockSequenceItem if levels.len == 0: case nextState @@ -605,7 +609,11 @@ proc doPresent(s: var YamlStream, target: PresenterTarget, raise newException(YamlPresenterJsonError, "Cannot have map as map key in JSON output!") nextState = dFlowMapStart - of psBlockOnly: nextState = dBlockMapValue + of psBlockOnly: + yAssert(not s.finished()) + let next = s.peek() + if next.kind == yamlEndMap: nextState = dFlowMapStart + else: nextState = dBlockMapValue if levels.len == 0: case nextState of dBlockMapValue: