-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Added codeRepr and dumpCode to the macros module. #5778
Conversation
This allows those writing macros to write examples, get the code to generate the AST for that example, and then modify that code to be dynamic with the macro function.
lib/core/macros.nim
Outdated
for i in 0..level-1: res.add " " | ||
res.add(")") | ||
|
||
if n.kind in {nnkEmpty, nnkNilLit, nnkCharLit..nnkInt64Lit, nnkFloatLit..nnkFloat64Lit, nnkStrLit..nnkTripleStrLit, nnkIdent, nnkSym, nnkNone}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dry?
lib/core/macros.nim
Outdated
## See also `repr`, `treeRepr`, and `lispRepr`. | ||
proc traverse(res: var string, level: int, n: NimNode) {.benign.} = | ||
for i in 0..level-1: res.add " " | ||
if n.kind in {nnkEmpty, nnkNilLit, nnkCharLit..nnkInt64Lit, nnkFloatLit..nnkFloat64Lit, nnkStrLit..nnkTripleStrLit, nnkIdent, nnkSym, nnkNone}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line too long.
Escaped characters for proper string handling Changed from new<>Node to newLit for applicable types
…rutils to avoid the import.
Add a test case please, but the code bloat bothers me. |
In what way is this different to |
@dom96
outputs:
outputs:
As you can see |
I see. It should get a different name then ( |
Hmm, a different name sure is possible. But not sure what you mean by the docs, I've tried to explain what it does in the doc-strings added to the file. If you have another wording I'd be happy to change it! |
I mean: show what this produces, just like you've shown above. |
Something like that? |
Add a test case please. |
This allows those writing macros to write examples, get the code to generate the AST for that example, and then modify that code to be dynamic with the macro function.