Skip to content

Commit

Permalink
Another useful form of isTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
zah committed Aug 14, 2019
1 parent 343c207 commit 4f685ab
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions stew/shims/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4f685ab

Please sign in to comment.