tmacro4.nim 361 B

123456789101112131415161718
  1. discard """
  2. output: "after"
  3. """
  4. import macros
  5. macro test_macro*(s: string, n: untyped): untyped =
  6. result = newNimNode(nnkStmtList)
  7. var ass : NimNode = newNimNode(nnkAsgn)
  8. add(ass, newIdentNode("str"))
  9. add(ass, newStrLitNode("after"))
  10. add(result, ass)
  11. when true:
  12. var str: string = "before"
  13. test_macro(str):
  14. var i : integer = 123
  15. echo str