macroshaxecompile-timenim-lang

Is it possible to globally modify the AST in Nim?


In Haxe, it's possible to iterate through and modify a project's entire AST prior to typing using @:build macros. I was wondering if it was possible to do something similar with Nim?

Nim has a rich and powerful macro API for AST reading and modification, but is this possible to do outside of explicit macro calls to the content held in other declarations? Could I, say for example, rewrite a specific function at compile-time prior to the generation of the output?

I feel like I've re-read the std/macros page and can't find any info on how to do this, is it possible and is there an example?


Solution

  • No, macros only have access to their corresponding subtree of the AST.