Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros-by-example expr metavariable substitution behaves as if parenthesized #1372

Open
8573 opened this issue Jun 26, 2023 · 2 comments
Open
Labels
A-macros Area: Macros

Comments

@8573
Copy link

8573 commented Jun 26, 2023

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.

@ehuss
Copy link
Contributor

ehuss commented Jun 26, 2023

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 😛).

@8573
Copy link
Author

8573 commented Jun 27, 2023

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.

@ehuss ehuss added the A-macros Area: Macros label Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: Macros
Projects
None yet
Development

No branches or pull requests

2 participants