Properly handle ':' after empty key in flow style

This commit is contained in:
Felix Krause 2016-03-17 18:57:14 +01:00
parent eda85be0b9
commit 06322505d1
1 changed files with 14 additions and 26 deletions

View File

@ -1539,6 +1539,8 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
of ':': of ':':
assert(level.kind == fplUnknown) assert(level.kind == fplUnknown)
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cFlow): if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cFlow):
handleFlowPlainScalar()
else:
level = ancestry.pop() level = ancestry.pop()
case level.kind case level.kind
of fplSequence, fplMapValue: of fplSequence, fplMapValue:
@ -1554,8 +1556,6 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
ancestry.add(level) ancestry.add(level)
level = FastParseLevel(kind: fplUnknown, indentation: -1) level = FastParseLevel(kind: fplUnknown, indentation: -1)
p.lexer.bufpos.inc() p.lexer.bufpos.inc()
else:
handleFlowPlainScalar()
of '\'': of '\'':
content = "" content = ""
startToken() startToken()
@ -1572,10 +1572,8 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
tag = yTagExclamationMark tag = yTagExclamationMark
yield scalarEvent(content, tag, anchor) yield scalarEvent(content, tag, anchor)
handleObjectEnd(fpFlowAfterObject) handleObjectEnd(fpFlowAfterObject)
of '!': of '!': handleTagHandle()
handleTagHandle() of '&': handleAnchor()
of '&':
handleAnchor()
of '*': of '*':
handleAlias() handleAlias()
state = fpFlowAfterObject state = fpFlowAfterObject
@ -1588,16 +1586,14 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
else: else:
explicitFlowKey = true explicitFlowKey = true
p.lexer.bufpos.inc() p.lexer.bufpos.inc()
else: else: handleFlowPlainScalar()
handleFlowPlainScalar()
of fpFlowAfterObject: of fpFlowAfterObject:
debug("state: flowAfterObject") debug("state: flowAfterObject")
p.lexer.skipWhitespaceCommentsAndNewlines() p.lexer.skipWhitespaceCommentsAndNewlines()
case p.lexer.buf[p.lexer.bufpos] case p.lexer.buf[p.lexer.bufpos]
of ']': of ']':
case level.kind case level.kind
of fplSequence: of fplSequence: discard
discard
of fplMapKey, fplMapValue: of fplMapKey, fplMapValue:
startToken() startToken()
parserError("Unexpected token (expected '}')") parserError("Unexpected token (expected '}')")
@ -1607,27 +1603,22 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
leaveFlowLevel() leaveFlowLevel()
of '}': of '}':
case level.kind case level.kind
of fplMapKey, fplMapValue: of fplMapKey, fplMapValue: discard
discard
of fplSequence: of fplSequence:
startToken() startToken()
parserError("Unexpected token (expected ']')") parserError("Unexpected token (expected ']')")
of fplUnknown, fplScalar: of fplUnknown, fplScalar: assert(false)
assert(false)
p.lexer.bufpos.inc() p.lexer.bufpos.inc()
leaveFlowLevel() leaveFlowLevel()
of ',': of ',':
case level.kind case level.kind
of fplSequence: of fplSequence: discard
discard
of fplMapValue: of fplMapValue:
yield scalarEvent("", yTagQuestionMark, yAnchorNone) yield scalarEvent("", yTagQuestionMark, yAnchorNone)
level.kind = fplMapKey level.kind = fplMapKey
explicitFlowKey = false explicitFlowKey = false
of fplMapKey: of fplMapKey: explicitFlowKey = false
explicitFlowKey = false of fplUnknown, fplScalar: assert(false)
of fplUnknown, fplScalar:
assert(false)
ancestry.add(level) ancestry.add(level)
level = FastParseLevel(kind: fplUnknown, indentation: -1) level = FastParseLevel(kind: fplUnknown, indentation: -1)
state = fpFlow state = fpFlow
@ -1637,10 +1628,8 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
of fplSequence, fplMapKey: of fplSequence, fplMapKey:
startToken() startToken()
parserError("Unexpected token (expected ',')") parserError("Unexpected token (expected ',')")
of fplMapValue: of fplMapValue: level.kind = fplMapValue
level.kind = fplMapValue of fplUnknown, fplScalar: assert(false)
of fplUnknown, fplScalar:
assert(false)
ancestry.add(level) ancestry.add(level)
level = FastParseLevel(kind: fplUnknown, indentation: -1) level = FastParseLevel(kind: fplUnknown, indentation: -1)
state = fpFlow state = fpFlow
@ -1654,6 +1643,5 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
else: else:
startToken() startToken()
parserError("Unexpected content (expected flow indicator)") parserError("Unexpected content (expected flow indicator)")
try: try: result = initYamlStream(backend)
result = initYamlStream(backend)
except Exception: assert(false) # compiler error except Exception: assert(false) # compiler error