mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 13:33:22 +00:00
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.
20 lines
390 B
Nim
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
|
|
|