mirror of https://github.com/status-im/NimYAML.git
Fixes #2
This commit is contained in:
parent
43e10f496a
commit
f2f340c0b6
|
@ -143,10 +143,14 @@ template handleObjectStart(k: YamlStreamEventKind) {.dirty.} =
|
|||
ancestry.add(level)
|
||||
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
||||
|
||||
template closeMoreIndentedLevels() {.dirty.} =
|
||||
template closeMoreIndentedLevels(atSequenceItem: bool = false) {.dirty.} =
|
||||
while ancestry.len > 0:
|
||||
let parent = ancestry[ancestry.high]
|
||||
if parent.indentation >= indentation:
|
||||
when atSequenceItem:
|
||||
if (indentation == level.indentation and level.kind == fplSequence) or
|
||||
(indentation == parent.indentation and level.kind == fplUnknown):
|
||||
break
|
||||
debug("Closing because parent.indentation (" & $parent.indentation &
|
||||
") >= indentation(" & $indentation & ")")
|
||||
yieldLevelEnd()
|
||||
|
@ -1115,7 +1119,7 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
|||
state = fpBlockObjectStart
|
||||
of lpdeSequenceItem:
|
||||
indentation = 0
|
||||
closeMoreIndentedLevels()
|
||||
closeMoreIndentedLevels(true)
|
||||
p.lexer.bufpos.inc()
|
||||
handleBlockSequenceIndicator()
|
||||
state = fpBlockObjectStart
|
||||
|
@ -1160,12 +1164,17 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
|||
state = fpBlockAfterPlainScalar
|
||||
of ' ':
|
||||
p.lexer.skipIndentation()
|
||||
if p.lexer.buf[p.lexer.bufpos] in ['\t', '\x0A', '\c', '#']:
|
||||
if p.lexer.buf[p.lexer.bufpos] in
|
||||
['\t', '\x0A', '\c', '#', EndOfFile]:
|
||||
p.lexer.lineEnding()
|
||||
handleLineEnd(true)
|
||||
else:
|
||||
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
||||
closeMoreIndentedLevels()
|
||||
if p.lexer.buf[p.lexer.bufpos] == '-' and not
|
||||
p.lexer.isPlainSafe(p.lexer.bufpos + 1, if flowdepth == 0:
|
||||
cBlockOut else: cFlowOut):
|
||||
closeMoreIndentedLevels(true)
|
||||
else: closeMoreIndentedLevels()
|
||||
case level.kind
|
||||
of fplScalar:
|
||||
state = fpBlockContinueScalar
|
||||
|
|
|
@ -270,4 +270,14 @@ suite "Parsing":
|
|||
test "Parsing: Empty lines between map elements":
|
||||
ensure("1: 2\n\n\n3: 4", startDocEvent(), startMapEvent(),
|
||||
scalarEvent("1"), scalarEvent("2"), scalarEvent("3"),
|
||||
scalarEvent("4"), endMapEvent(), endDocEvent())
|
||||
scalarEvent("4"), endMapEvent(), endDocEvent())
|
||||
test "Parsing: Sequence beginning at same line as map key":
|
||||
ensure("1:\n- 2\n- 3\n4: 5", startDocEvent(), startMapEvent(),
|
||||
scalarEvent("1"), startSeqEvent(), scalarEvent("2"),
|
||||
scalarEvent("3"), endSeqEvent(), scalarEvent("4"),
|
||||
scalarEvent("5"), endMapEvent(), endDocEvent())
|
||||
test "Parsing: Sequence beginning at same line as map key with > 0 indent":
|
||||
ensure(" foo:\n - bar\n baz:", startDocEvent(), startMapEvent(),
|
||||
scalarEvent("foo"), startSeqEvent(), scalarEvent("bar"),
|
||||
endSeqEvent(), scalarEvent("baz"), scalarEvent(""),
|
||||
endMapEvent(), endDocEvent())
|
Loading…
Reference in New Issue