From 4f685ab7eca66e39a720e8e9468df1c55fd663f9 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 14 Aug 2019 17:29:14 +0200 Subject: [PATCH] Another useful form of isTuple --- stew/shims/macros.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stew/shims/macros.nim b/stew/shims/macros.nim index 0104bb4..31eb6b6 100644 --- a/stew/shims/macros.nim +++ b/stew/shims/macros.nim @@ -24,13 +24,15 @@ proc findPragma*(pragmas: NimNode, pragmaSym: NimNode): NimNode = return p func isTuple*(t: NimNode): bool = - t.kind == nnkBracketExpr and t[0].kind == nnkSym and t[0].repr == "tuple" + t.kind == nnkBracketExpr and t[0].kind == nnkSym and eqIdent(t[0], "tuple") + +macro isTuple*(T: type): untyped = + newLit(isTuple(getType(T)[1])) template readPragma*(field: FieldDescription, pragmaName: static string): NimNode = let p = findPragma(field.pragmas, bindSym(pragmaName)) if p != nil and p.len == 2: p[1] else: p - proc recordFields*(typeImpl: NimNode): seq[FieldDescription] = # TODO: This doesn't support inheritance yet if typeImpl.isTuple: