clean up `constructJson` by removing not needed assignments

Also use `expKey` everywhere.
This commit is contained in:
Vindaar 2018-10-11 14:38:48 +02:00 committed by flyx
parent 3eb006be2d
commit c4e7072722
1 changed files with 2 additions and 5 deletions

View File

@ -142,7 +142,6 @@ proc constructJson*(s: var YamlStream): seq[JsonNode]
let jsonScalar = jsonFromScalar(event.scalarContent, let jsonScalar = jsonFromScalar(event.scalarContent,
event.scalarTag) event.scalarTag)
levels[levels.high].node[levels[levels.high].key] = jsonScalar levels[levels.high].node[levels[levels.high].key] = jsonScalar
levels[levels.high].key = ""
levels[levels.high].expKey = true levels[levels.high].expKey = true
if event.scalarAnchor != yAnchorNone: if event.scalarAnchor != yAnchorNone:
anchors[event.scalarAnchor] = jsonScalar anchors[event.scalarAnchor] = jsonScalar
@ -154,12 +153,11 @@ proc constructJson*(s: var YamlStream): seq[JsonNode]
case levels[levels.high].node.kind case levels[levels.high].node.kind
of JArray: levels[levels.high].node.elems.add(level.node) of JArray: levels[levels.high].node.elems.add(level.node)
of JObject: of JObject:
if levels[levels.high].key.len == 0: if levels[levels.high].expKey:
raise newException(YamlConstructionError, raise newException(YamlConstructionError,
"non-scalar as key not allowed in JSON") "non-scalar as key not allowed in JSON")
else: else:
levels[levels.high].node[levels[levels.high].key] = level.node levels[levels.high].node[levels[levels.high].key] = level.node
levels[levels.high].key = ""
levels[levels.high].expKey = true levels[levels.high].expKey = true
else: else:
internalError("Unexpected node kind: " & internalError("Unexpected node kind: " &
@ -173,13 +171,12 @@ proc constructJson*(s: var YamlStream): seq[JsonNode]
levels[levels.high].node.elems.add( levels[levels.high].node.elems.add(
anchors.getOrDefault(event.aliasTarget)) anchors.getOrDefault(event.aliasTarget))
of JObject: of JObject:
if levels[levels.high].key.len == 0: if levels[levels.high].expKey:
raise newException(YamlConstructionError, raise newException(YamlConstructionError,
"cannot use alias node as key in JSON") "cannot use alias node as key in JSON")
else: else:
levels[levels.high].node.fields.add( levels[levels.high].node.fields.add(
levels[levels.high].key, anchors.getOrDefault(event.aliasTarget)) levels[levels.high].key, anchors.getOrDefault(event.aliasTarget))
levels[levels.high].key = ""
levels[levels.high].expKey = true levels[levels.high].expKey = true
else: else:
internalError("Unexpected node kind: " & $levels[levels.high].node.kind) internalError("Unexpected node kind: " & $levels[levels.high].node.kind)