Merge pull request #7965 from hlaaftana/patch-3

Allow `%` overloading in `%*` macro in json (again)
This commit is contained in:
Andreas Rumpf 2018-06-06 10:51:42 +02:00 • committed by GitHub
commit 97cf2a309a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -328,14 +328,14 @@ proc toJson(x: NimNode): NimNode {.compiletime.} =
result = newNimNode(nnkBracket) result = newNimNode(nnkBracket)
for i in 0 ..< x.len: for i in 0 ..< x.len:
result.add(toJson(x[i])) result.add(toJson(x[i]))
result = newCall(bindSym"%", result) result = newCall(bindSym("%", brOpen), result)
of nnkTableConstr: # object of nnkTableConstr: # object
if x.len == 0: return newCall(bindSym"newJObject") if x.len == 0: return newCall(bindSym"newJObject")
result = newNimNode(nnkTableConstr) result = newNimNode(nnkTableConstr)
for i in 0 ..< x.len: for i in 0 ..< x.len:
x[i].expectKind nnkExprColonExpr x[i].expectKind nnkExprColonExpr
result.add newTree(nnkExprColonExpr, x[i][0], toJson(x[i][1])) result.add newTree(nnkExprColonExpr, x[i][0], toJson(x[i][1]))
result = newCall(bindSym"%", result) result = newCall(bindSym("%", brOpen), result)
of nnkCurly: # empty object of nnkCurly: # empty object
x.expectLen(0) x.expectLen(0)
result = newCall(bindSym"newJObject") result = newCall(bindSym"newJObject")
@ -343,9 +343,9 @@ proc toJson(x: NimNode): NimNode {.compiletime.} =
result = newCall(bindSym"newJNull") result = newCall(bindSym"newJNull")
of nnkPar: of nnkPar:
if x.len == 1: result = toJson(x[0]) if x.len == 1: result = toJson(x[0])
else: result = newCall(bindSym"%", x) else: result = newCall(bindSym("%", brOpen), x)
else: else:
result = newCall(bindSym"%", x) result = newCall(bindSym("%", brOpen), x)
macro `%*`*(x: untyped): untyped = macro `%*`*(x: untyped): untyped =
## Convert an expression to a JsonNode directly, without having to specify ## Convert an expression to a JsonNode directly, without having to specify