Files
Nim/tests/macros/tmacro4.nim
zah 1be0022e7c Fixes #5167 and related problems (#5475)
This commit returns to a bit less strict checking of the number
of macro arguments, because some old immediate macros rely on a
behavior where even the arity of the macro is not being checked.

It may be better if such macros are just declared to use varargs[expr],
but this remains for another day.
2017-03-12 09:33:49 +01:00

20 lines
390 B
Nim

discard """
output: "after"
"""
import
macros, strutils
macro test_macro*(s: string, n: stmt): stmt {.immediate.} =
result = newNimNode(nnkStmtList)
var ass : NimNode = newNimNode(nnkAsgn)
add(ass, newIdentNode("str"))
add(ass, newStrLitNode("after"))
add(result, ass)
when isMainModule:
var str: string = "before"
test_macro(str):
var i : integer = 123
echo str