-
Notifications
You must be signed in to change notification settings - Fork 23
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
RFC: AST comments should be properly exposed #150
Comments
+1 if you will remove comment field from the |
Furthermore the upcoming version 0.20 will be about making the AST stable, that includes a spec for |
+1 for finally addressing this issue, it's a real enabler for a number of tools
I'm not sure what was wrong with that logic? In any case, if AST comments are coming soon, I'd be ok.
what would be a counter example?
what type of user code could break, given that Note that with accessors, we'd mitigate the risk of breaking changes since we'd be able to use notewhile we're talking about attaching comment nodes to AST, we should also look at fixing current defects in where |
I also wonder why we don't just expose a A new AST node is nice, but I don't think it really offers enough advantage to just having the existing |
This discussion is here, so you can post one if you find it. Then you would proof my assumption to be wrong.
Macros would break. For example
The comment field in |
Nothing but Nim benefits from using the same AST that the compiler itself uses. It keeps us honest about what can be done with it, it keeps the bar for entering Nim compiler development low. |
The clarity in the Nim grammar it brings and for docgen related tooling is enough of an advantage. Besides, the AST changed in 0.19.9 slightly because of other reasons, previously for-loop inlining was done in a |
very nice. it's interesting also to build custom tools for automated refactoring - an ideal AST would retain all information necessary to recreate the exact original source file byte by byte.. see for example clang-tidy and how it can be used to refactor old c++ into new c++ (unique_ptr, auto, etc).. imagine applying that to the std lib and all the crufty stuff in there.. |
@arnetheduck normal comments are still not part of the AST. They cannot be retained. EDIT: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 7 days. |
Problem
currently the AST has internally a field
comment
, so that documentation comments can be attached to everything. But this field is not exposed via macros, and it should not be. ANimNode
(PNode
in the compiler) has a crampedlineinfo
with only a few bits for line and column information. People already hit it's limits. On the other hand, there is a comment field in every node that doesn't contain information at all. Most of the time it is unused.Goal
This change should remove on one hand this general comment field from NimNode, and only allow documentation comments at certain positions in the AST. On the other hand, when there is a documentation comment, it should be easily visible in the AST, and therefore not just available to use for macros, but also visible with
treeRepr
. Illegal documentation comments should be detected as such (normal comments are still valid everywhere).Solution
Documentation comments only make sense for identifiers that can potentially be exported: var, let, const, proc, template, etc. Here the identifier handling is already special cased. Sometimes the AST has only an identifier, sometimes it is the * postfix operator on the identifier. Nim doesn't have postfix operators, the postfix operator is only used to tag symbols as exported. Here the postfix operator can easily be substituted with a node of length 3 that contains the identifier, the information the tag, if the nodes is exported and the documentation comment, if it exists.
last words
This is a breaking change, so feedback is welcome. But it will be a solution for documentation comments. They will either be properly attached to the AST visibly, or they will cause an error/warning in the compiler. So when the compiler finds a documentation comment but can't attach it properly to the AST, it will no longer just disappear.
The text was updated successfully, but these errors were encountered: