reference
reference copied to clipboard
Macros-by-example `expr` metavariable substitution behaves as if parenthesized
While reviewing some code, I saw a macro-by-example using a metavariable of type expr in such a way that the code would be wrong if an expression were given to the macro that needed to be parenthesized — so I thought. Testing in the Playground, I found that substituted expressions appeared to be parenthesized automatically. I checked the Reference's section on macros-by-example and saw nothing about this; I looked at the Book's section on macros-by-example and saw nothing about this, but the Book suggested for further reading https://veykril.github.io/tlborm/, which explains that expressions are substituted as AST nodes rather than as tokens and so behave as if parenthesized. I suggest that this be mentioned in the Reference.
The section at Forwarding a matched fragment mentions that fragments are treated as opaque AST elements. Does that cover what you are looking for?
For the most part, expansion is only very partially documented. Eventually I would expect it to have a dedicated chapter (or five 😛).
The section at Forwarding a matched fragment mentions that fragments are treated as opaque AST elements. Does that cover what you are looking for?
Maybe I don't have enough reference-level understanding to see it, but I don't think so; I think that only addresses matching of the fragment by further macros, rather than how a fragment substituted into the macro's output is treated when the final, post-all-macro-expansion code is processed by the rest of the compiler.