Fixed bugs

* lexer did not handle indentation indicator for block scalars properly
 * transform() did not work properly for string output
This commit is contained in:
Felix Krause 2016-12-13 21:22:36 +01:00
parent c2041b44d1
commit 87bfcd1490
2 changed files with 7 additions and 5 deletions

View File

@ -792,7 +792,7 @@ proc blockScalarHeader[T](lex: YamlLexer): bool =
of '1'..'9': of '1'..'9':
if lex.blockScalarIndent != UnknownIndentation: if lex.blockScalarIndent != UnknownIndentation:
raise generateError[T](lex, "Only one indentation indicator is allowed") raise generateError[T](lex, "Only one indentation indicator is allowed")
lex.blockScalarIndent = ord(lex.c) - ord('\x30') lex.blockScalarIndent = ord(lex.c) - ord('\x30') + lex.indentation
of spaceOrLineEnd: break of spaceOrLineEnd: break
else: else:
raise generateError[T](lex, raise generateError[T](lex,
@ -870,6 +870,7 @@ proc blockScalarLineStart[T](lex: YamlLexer, recentWasMoreIndented: var bool):
proc blockScalar[T](lex: YamlLexer): bool = proc blockScalar[T](lex: YamlLexer): bool =
debug("lex: blockScalar") debug("lex: blockScalar")
lex.indentation = 0
block outer: block outer:
var recentWasMoreIndented = true var recentWasMoreIndented = true
if lex.blockScalarIndent == UnknownIndentation: if lex.blockScalarIndent == UnknownIndentation:
@ -895,8 +896,6 @@ proc blockScalar[T](lex: YamlLexer): bool =
break outer break outer
lex.indentation = lex.blockScalarIndent lex.indentation = lex.blockScalarIndent
break break
else:
lex.blockScalarIndent += lex.indentation
if lex.c notin {'.', '-'} or lex.indentation == 0: if lex.c notin {'.', '-'} or lex.indentation == 0:
if not blockScalarLineStart[T](lex, recentWasMoreIndented): break outer if not blockScalarLineStart[T](lex, recentWasMoreIndented): break outer
else: else:

View File

@ -761,8 +761,11 @@ proc doTransform(input: Stream | string, output: PresenterTarget,
event.scalarTag = yTagString event.scalarTag = yTagString
BufferYamlStream(bys).put(event) BufferYamlStream(bys).put(event)
else: BufferYamlStream(bys).put(e) else: BufferYamlStream(bys).put(e)
present(bys, output, tagLib, options) when output is ptr[string]: output[] = present(bys, tagLib, options)
else: present(events, output, tagLib, options) else: present(bys, output, tagLib, options)
else:
when output is ptr[string]: output[] = present(events, tagLib, options)
else: present(events, output, tagLib, options)
except YamlStreamError: except YamlStreamError:
var e = getCurrentException() var e = getCurrentException()
while e.parent of YamlStreamError: e = e.parent while e.parent of YamlStreamError: e = e.parent