You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
even with the example. I'm also vary of macros because most Rust tooling breaks down (formatting, autocompletion) and can be difficult to understand if you haven't used the macro before.
Have you considered alternative mutation APIs? E.g. Rome has two APIs:
SyntaxFactory::new_if_stmt(condition, body) for the creation of nodes
Node::with_X(x) -> Node methods for returning a new copy with X set to a specific value.
This allows, in combination, to write SyntaxFactory::new_if_stmt(condition, body).with_orelse(orelse).
I'm also vary of macros because most Rust tooling breaks down (formatting, autocompletion) and can be difficult to understand if you haven't used the macro before.
Unlike other macros, the linked smart_quote! doesn't break tools due to the similar restriction - it must be always a valid rust code.
One good thing about it is python_ast! doesn't include any rust code inside. It only requires python code and binding list of variables.
Activity
MichaReiser commentedon May 18, 2023
I'm struggling to understand what's happening in
even with the example. I'm also vary of macros because most Rust tooling breaks down (formatting, autocompletion) and can be difficult to understand if you haven't used the macro before.
Have you considered alternative mutation APIs? E.g. Rome has two APIs:
SyntaxFactory::new_if_stmt(condition, body)for the creation of nodesNode::with_X(x) -> Nodemethods for returning a new copy withXset to a specific value.This allows, in combination, to write
SyntaxFactory::new_if_stmt(condition, body).with_orelse(orelse).youknowone commentedon May 18, 2023
It turns a python snippet to python ast with given values. It has very different user experience to factories.
Starting from simpler example
will be parsed to
The factory will be somewhere between it, but it will be more close to the latter.
Simple value example
will turned into
By looking in every node and checking its identifier name
new_function_nameis same as the given Vars list.More complex one, similar to the original example.
will be originally parsed to:
and then folded to
More with comprehension
originally turns into
and then folded to
youknowone commentedon May 18, 2023
Unlike other macros, the linked
smart_quote!doesn't break tools due to the similar restriction - it must be always a valid rust code.One good thing about it is
python_ast!doesn't include any rust code inside. It only requires python code and binding list of variables.