Closed Boshen closed 1 month ago
On this subject, one thing that makes me struggle is that I can't find a clear way to get AstNode
from a given ast struct/enum. How should it be done? I guess it is possible to search for it through the nodes but I was looking for a faster way.
I'm looking for a way to get either AstNode
or the AstNodeId
for a given expression(or any other AST type for that matter).
Is it possible to add the ast_node_id to every AST node referencable via an AstNode? It can be stored in a cell similar to identifiers so we can assign them in the semantic.
It will make getting the node's parent, etc easier and would eliminate the need to pass reference on enter_node and leave_node while also providing a way to access the AstNode in VisitMut, Both enter and leave events can pass the AstNodeId instead of AstNode, and we can also access the AstNode easily within our visit methods.
Right now I can't see any clear way to access an AstNode from its let's say expression, statement, etc.
Having AstNodeId on the struct itself would also allow us to get rid of the AstNode
structure and make the AstNodes
struct SOA.
The requirement for ast_node_id
has been brought up a couple times in the past, I think it's worthy to create a separate issue, bike-shed it and then implement it.
We're working on it...
While I was working with
syn
, I found the documentation on AST nodes really helpful, we should do the same.https://docs.rs/syn/latest/syn/index.html#structs