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':
if lex.blockScalarIndent != UnknownIndentation:
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
else:
raise generateError[T](lex,
@ -870,6 +870,7 @@ proc blockScalarLineStart[T](lex: YamlLexer, recentWasMoreIndented: var bool):
proc blockScalar[T](lex: YamlLexer): bool =
debug("lex: blockScalar")
lex.indentation = 0
block outer:
var recentWasMoreIndented = true
if lex.blockScalarIndent == UnknownIndentation:
@ -895,8 +896,6 @@ proc blockScalar[T](lex: YamlLexer): bool =
break outer
lex.indentation = lex.blockScalarIndent
break
else:
lex.blockScalarIndent += lex.indentation
if lex.c notin {'.', '-'} or lex.indentation == 0:
if not blockScalarLineStart[T](lex, recentWasMoreIndented): break outer
else:

View File

@ -761,7 +761,10 @@ proc doTransform(input: Stream | string, output: PresenterTarget,
event.scalarTag = yTagString
BufferYamlStream(bys).put(event)
else: BufferYamlStream(bys).put(e)
present(bys, output, tagLib, options)
when output is ptr[string]: output[] = present(bys, 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:
var e = getCurrentException()