Fixed undeclared possible IndexError from queues

This commit is contained in:
Felix Krause 2016-06-26 12:37:15 +02:00
parent eab44a99ed
commit fb05fcc95f
1 changed files with 9 additions and 1 deletions

View File

@ -321,6 +321,14 @@ proc writeTagAndAnchor(target: Stream, tag: TagId, tagLib: TagLibrary,
e.parent = getCurrentException() e.parent = getCurrentException()
raise e raise e
proc nextItem(c: var Queue, s: var YamlStream):
YamlStreamEvent {.raises: [YamlStreamError].} =
if c.len > 0:
try: result = c.dequeue
except IndexError: assert false
else:
result = s.next()
proc present*(s: var YamlStream, target: Stream, tagLib: TagLibrary, proc present*(s: var YamlStream, target: Stream, tagLib: TagLibrary,
options: PresentationOptions = defaultPresentationOptions) = options: PresentationOptions = defaultPresentationOptions) =
var var
@ -330,7 +338,7 @@ proc present*(s: var YamlStream, target: Stream, tagLib: TagLibrary,
let newline = if options.newlines == nlLF: "\l" let newline = if options.newlines == nlLF: "\l"
elif options.newlines == nlCRLF: "\c\l" else: "\n" elif options.newlines == nlCRLF: "\c\l" else: "\n"
while cached.len > 0 or not s.finished(): while cached.len > 0 or not s.finished():
let item = if cached.len > 0: cached.dequeue else: s.next() let item = nextItem(cached, s)
case item.kind case item.kind
of yamlStartDoc: of yamlStartDoc:
if options.style != psJson: if options.style != psJson: