mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 01:44:37 +00:00
21 lines
389 B
Nim
21 lines
389 B
Nim
|
|
type PNode* = ref object of RootObj
|
|
|
|
template litNode(name, ty) =
|
|
type name* = ref object of PNode
|
|
val*: ty
|
|
litNode PIntNode, int
|
|
|
|
import json
|
|
|
|
template withKey*(j: JsonNode; key: string; varname,
|
|
body: untyped): typed =
|
|
if j.hasKey(key):
|
|
let varname{.inject.}= j[key]
|
|
block:
|
|
body
|
|
|
|
var j = parsejson("{\"zzz\":1}")
|
|
withkey(j, "foo", x):
|
|
echo(x)
|