我需要将语句列表拆分为多个部分,如下所示:
import macros
macro test: stmt =
var first = quote do:
var x = 1
var second = quote do:
echo x
result = newStmtList()
first.copyChildrenTo(result)
second.copyChildrenTo(result)
echo result.repr
test
但是编译器告诉我:
[..]
var x = 1
echo x
minimalist.nim(14, 0) Info: instantiation from here
minimalist.nim(7, 13) Error: undeclared identifier: 'x'
echo x
x
鉴于在节点列表中声明,这非常令人困惑。我怎样才能使它正常工作?(如果不是很明显,由于其他原因,我确实需要将 AST 分成多个部分)