Skip to content

Instantly share code, notes, and snippets.

@zacharycarter
Created August 9, 2019 19:37
Show Gist options
  • Save zacharycarter/e43526242ae2b5e28ec4d53e07817a9e to your computer and use it in GitHub Desktop.
Save zacharycarter/e43526242ae2b5e28ec4d53e07817a9e to your computer and use it in GitHub Desktop.
proc handleSetSeq(oId: NimNode, pnId: NimNode, sId: NimNode, name: string, dtype: NimNode): NimNode =
let
seqKind = dtype.nodeToVal().strVal
fieldName = ident(name)
eceId = ident"e"
bnId = ident"b"
result = quote do:
var `eceId` = nkExprColonExpr.newTree(
newSymNode(`sId`),
)
var `bnId` = nkBracket.newTree()
for val in `oid`.`fieldName`:
case `seqKind`
of "floatVal":
`bnId`.add nkFloatLit.newFloatNode(parseFloat(val))
`eceId`.add `bnId`
of "intVal":
`bnId`.add nkIntLit.newIntNode(parseInt(val))
`eceId`.add `bnId`
of "strVal":
`bnId`.add nkStrLit.newStrNode(val)
`eceId`.add `bnId`
else:
discard
`pnId`.add `eceId`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment