Skip to content

Instantly share code, notes, and snippets.

@Vindaar
Created August 9, 2019 20:03
Show Gist options
  • Save Vindaar/15cba3d524c6b73e36546fd52ad551b7 to your computer and use it in GitHub Desktop.
Save Vindaar/15cba3d524c6b73e36546fd52ad551b7 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"
var forBody = newStmtList()
case seqKind
of "floatVal":
forBody.add quote do:
`bnId`.add nkFloatLit.newFloatNode(val)
of "intVal":
forBody.add quote do:
`bnId`.add nkIntLit.newIntNode(val)
of "strVal":
forBody.add quote do:
`bnId`.add nkStrLit.newStrNode(val)
forBody.add quote do:
`eceId`.add `bnId`
result = quote do:
var `eceId` = nkExprColonExpr.newTree(
newSymNode(`sId`),
)
var `bnId` = nkBracket.newTree()
forBody = quote do:
for val in `oid`.`fieldName`:
`forBody`
result.add quote do:
`pnId`.add `eceId`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment