Small improvements

This commit is contained in:
Felix Krause 2016-01-24 21:21:37 +01:00
parent 36872370d5
commit f2c81f1fc5
2 changed files with 6 additions and 7 deletions

View File

@ -164,7 +164,7 @@ proc present*(s: YamlStream, target: Stream, tagLib: TagLibrary,
if finished(s):
break
cached.enqueue(item)
except:
except Exception:
var e = newException(YamlPresenterStreamError, "")
e.parent = getCurrentException()
raise e
@ -257,7 +257,7 @@ proc present*(s: YamlStream, target: Stream, tagLib: TagLibrary,
else:
length = high(int)
break
except:
except Exception:
var e = newException(YamlPresenterStreamError, "")
e.parent = getCurrentException()
raise e
@ -322,7 +322,7 @@ proc present*(s: YamlStream, target: Stream, tagLib: TagLibrary,
break
else:
mps = mpNeedBlock
except:
except Exception:
var e = newException(YamlPresenterStreamError, "")
e.parent = getCurrentException()
raise e
@ -448,7 +448,7 @@ proc present*(s: YamlStream, target: Stream, tagLib: TagLibrary,
if finished(s):
break
cached.enqueue(next)
except:
except Exception:
var e = newException(YamlPresenterStreamError, "")
e.parent = getCurrentException()
raise e

View File

@ -144,7 +144,7 @@ macro serializable*(types: stmt): stmt =
while event.kind != yamlEndMap:
assert event.kind == yamlScalar
assert event.scalarTag in [yTagQuestionMark, yTagString]
case hash(event.scalarContent)
case event.scalarContent
else:
raise newException(YamlConstructionError,
"Unknown key for " & `tName` & ": " &
@ -154,9 +154,8 @@ macro serializable*(types: stmt): stmt =
var keyCase = impl[5][1][2]
assert keyCase.kind == nnkCaseStmt
for field in objectFields(recList):
let nameHash = hash($field.name.ident)
keyCase.insert(1, newNimNode(nnkOfBranch).add(
newIntLitNode(nameHash)).add(newStmtList(
newStrLitNode($field.name.ident)).add(newStmtList(
newCall("construct", [newIdentNode("s"), newDotExpr(
newIdentNode("result"), field.name)])
))