Why not try it? Here's example implementation:
import std/[macros]
macro foo(): untyped =
result = newStmtList(
infix(
newLit(1),
"*",
infix(
newLit(2),
"+",
newLit(3)
)
)
Because
1 + 2 * 3
Run
will become
Infix
Ident "+"
IntLit 1
Infix
Ident "*"
IntLit 2
IntLit 3
Run
or alike, while
(1 + 2) * 3
Run
becomes
Infix
Ident "
Why wouldn't your example be valid? The compiler checks the AST after macro
expansion, it can reject it and produce an error message.
To be honest, I doubt I understood your question.
What will happen if the AST generated by a macro is obviously artificial or
unnatural (that will never come from the code parser)?
For example,
Infix
Ident "*"
Infix
Ident "+"
IntLit 1
IntLit 2
IntLit 3
Run
Is it still vaild?