Some helpers shared between nim-serialization and nim-confutils

This commit is contained in:
Zahary Karadjov 2019-07-03 02:30:30 +03:00
parent 7fa381eb8d
commit 421fd009d4
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 7 additions and 0 deletions

View File

@ -23,6 +23,10 @@ proc findPragma*(pragmas: NimNode, pragmaSym: NimNode): NimNode =
if p.kind in nnkPragmaCallKinds and p.len > 0 and eqIdent(p[0], pragmaSym):
return p
template readPragma*(field: FieldDescription, pragmaName: static string): NimNode =
let p = field.pragmas.findPragma bindSym(pragmaName)
if p != nil and p.len == 2: p[1] else: p
iterator recordFields*(typeImpl: NimNode): FieldDescription =
# TODO: This doesn't support inheritance yet
let
@ -114,6 +118,9 @@ iterator recordFields*(typeImpl: NimNode): FieldDescription =
if traversalStack.len == 0: break
macro field*(obj: typed, fieldName: static string): untyped =
newDotExpr(obj, ident fieldName)
proc skipPragma*(n: NimNode): NimNode =
if n.kind == nnkPragmaExpr: n[0]
else: n