Skip to content

Instantly share code, notes, and snippets.

@Clyybber
Last active January 27, 2019 19:15
Show Gist options
  • Save Clyybber/7655fb852dafa701a3ee7847c5b51b10 to your computer and use it in GitHub Desktop.
Save Clyybber/7655fb852dafa701a3ee7847c5b51b10 to your computer and use it in GitHub Desktop.
with macro
import macros
macro with*(obj: typed, statements: untyped): untyped =
#let statements =
# if body.kind == nnkDo: body[6]
# else: body
statements.expectKind(nnkStmtList)
result = newStmtList()
for statement in statements:
case statement.kind:
of nnkAsgn:
result.add(
newAssignment(
newDotExpr(obj, statement[0]),
statement[1]
)
)
of nnkCall:
result.add(
newCall(
newDotExpr(obj, statement[0])
)
)
else: discard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment