Files
Nim/tests/template/tissue993.nim
2014-03-13 22:29:48 +01:00

22 lines
413 B
Nim

type pnode* = ref object of tobject
template litNode (name, ty): stmt =
type name* = ref object of PNode
val*: ty
litNode PIntNode, int
import json
template withKey*(j: PJsonNode; key: string; varname: expr;
body:stmt): stmt {.immediate.} =
if j.hasKey(key):
let varname{.inject.}= j[key]
block:
body
var j = parsejson("{\"zzz\":1}")
withkey(j, "foo", x):
echo(x)