summary refs log tree commit diff stats
path: root/tests/template/tissue993.nim
blob: dae9df6832478d234205039b1b29f4d65c33b607 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
type PNode* = ref object of RootObj

template litNode (name, ty): stmt  =
  type name* = ref object of PNode
    val*: ty
litNode PIntNode, int

import json

template withKey*(j: JsonNode; 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)