fastparse: Improvements to flow parsing

This commit is contained in:
Felix Krause 2016-01-22 22:40:22 +01:00
parent f670c5c86b
commit c89f07e1fd
2 changed files with 10 additions and 2 deletions

View File

@ -1076,7 +1076,11 @@ proc fastparse*(tagLib: TagLibrary, s: Stream): YamlStream =
anchor = yAnchorNone anchor = yAnchorNone
level.kind = fplMapKey level.kind = fplMapKey
of fplMapKey: of fplMapKey:
discard if tag != yTagQuestionmark or anchor != yAnchorNone:
yield scalarEvent("", tag, anchor)
tag = yTagQuestionmark
anchor = yAnchorNone
yield scalarEvent("", tag, anchor)
of fplSequence: of fplSequence:
raiseError("Unexpected token (expected ']')", lexer.bufpos) raiseError("Unexpected token (expected ']')", lexer.bufpos)
of fplUnknown, fplScalar: of fplUnknown, fplScalar:
@ -1088,7 +1092,10 @@ proc fastparse*(tagLib: TagLibrary, s: Stream): YamlStream =
level = ancestry.pop() level = ancestry.pop()
case level.kind case level.kind
of fplSequence: of fplSequence:
yield endSeqEvent() if tag != yTagQuestionmark or anchor != yAnchorNone:
yield scalarEvent("", tag, anchor)
tag = yTagQuestionmark
anchor = yAnchorNone
of fplMapKey, fplMapValue: of fplMapKey, fplMapValue:
raiseError("Unexpected token (expected '}')", lexer.bufpos) raiseError("Unexpected token (expected '}')", lexer.bufpos)
of fplUnknown, fplScalar: of fplUnknown, fplScalar:

View File

@ -124,6 +124,7 @@ proc constructJson*(s: YamlStream): seq[JsonNode] =
levels[levels.high].node.elems.add(level.node) levels[levels.high].node.elems.add(level.node)
of JObject: of JObject:
if isNil(levels[levels.high].key): if isNil(levels[levels.high].key):
echo level.node.pretty()
raise newException(ValueError, raise newException(ValueError,
"non-scalar as key not allowed in JSON") "non-scalar as key not allowed in JSON")
else: else: