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

documentation of {.noRewrite.} pragma is missing #9454

Closed
mratsim opened this issue Oct 20, 2018 · 1 comment · Fixed by #11453
Closed

documentation of {.noRewrite.} pragma is missing #9454

mratsim opened this issue Oct 20, 2018 · 1 comment · Fixed by #11453
Labels
Documentation Content Related to documentation content (not generation). Easy Macros Pragmas Templates

Comments

@mratsim
Copy link
Collaborator

mratsim commented Oct 20, 2018

While looking into term-rewriting macros recursion, I realised that the one true fix to #9288 #8376 and #2901 mentioned in the doc PR #9305 was introduced in 2015, the forgotten {.noRewrite.} pragma 4674b3e.

It's completely undocumented though and I'm not even sure @Araq was aware of it:

Introduce {.noRewrite.} expr pragma disabling TR

Term rewriting macros/templates are currently greedy and they will rewrite as
long as there is a match. So there was no way to ensure some rewrite happens
only once, eg. when rewriting term to same term plus extra content.

With new macro we can actually prevent further rewriting on marked expr or
stmts, eg. with given example echo(...) will be rewritten just once:

template pwnEcho{echo(x)}(x: expr) =
  {.noRewrite.}: echo("pwned!")

echo "ab"

cc @andreaferretti @kaushalmodi @reactormonk

@mratsim mratsim added Documentation Content Related to documentation content (not generation). Templates Macros Easy labels Oct 20, 2018
@krux02 krux02 changed the title Document the {.noRewrite.} pragma to control recursion in term-rewriting macros documentation of {.noRewrite.} pragma is missing Oct 20, 2018
@Araq
Copy link
Member

Araq commented Oct 22, 2018

I'm aware but I don't think it's a good idea to document it, this solution doesn't feel right.

Araq pushed a commit that referenced this issue Jun 13, 2019
* fixes #9454
* Peer review feedback, wording, move to experimental manual
narimiran pushed a commit to narimiran/Nim that referenced this issue Jun 16, 2019
* fixes nim-lang#9454
* Peer review feedback, wording, move to experimental manual

(cherry picked from commit 80320c7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Content Related to documentation content (not generation). Easy Macros Pragmas Templates
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants