tmacro4.nim 373 B

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