-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Auto generate ast expression nodes #16285
base: main
Are you sure you want to change the base?
Changes from 1 commit
85c9400
18f64ea
cfad8f4
8b9bbb6
ce4cf6f
afba5fb
4951013
6f28c81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,13 +81,6 @@ anynode_is_label = "expression" | |
rustdoc = "/// See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)" | ||
|
||
[Expr.nodes] | ||
ExprBoolOp = {} | ||
ExprNamed = {} | ||
ExprBinOp = {} | ||
ExprUnaryOp = {} | ||
ExprLambda = {} | ||
ExprIf = {} | ||
ExprDict = {} | ||
ExprSet = {} | ||
ExprListComp = {} | ||
ExprSetComp = {} | ||
|
@@ -113,6 +106,35 @@ ExprList = {} | |
ExprTuple = {} | ||
ExprSlice = {} | ||
ExprIpyEscapeCommand = {} | ||
ExprBoolOp = { fields = [ | ||
{ name = "op", type = "BoolOp" }, | ||
{ name = "values", type = "Expr", seq = true } | ||
]} | ||
ExprNamed = { fields = [ | ||
{ name = "target", type = "Expr" }, | ||
{ name = "value", type = "Expr" } | ||
]} | ||
ExprBinOp = { fields = [ | ||
{ name = "left", type = "Expr" }, | ||
{ name = "op", type = "Operator" }, | ||
{ name = "right", type = "Expr" } | ||
]} | ||
ExprUnaryOp = { fields = [ | ||
{ name = "op", type = "UnaryOp" }, | ||
{ name = "operand", type = "Expr" } | ||
]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a style nit, the following are equivalent TOML (i.e., it shouldn't require changes to the generator) that I think might be a bit easier to read: [Expr.nodes.ExprUnaryOp]
fields = [
{ name = "op", type = "UnaryOp" },
{ name = "operand", type = "Expr" }
] or [[Expr.nodes.ExprUnaryOp.fields]]
name = "op"
type = "UnaryOp"
[[Expr.nodes.ExprUnaryOp.fields]]
name = "operand"
type = "Expr" I have a slight preference for the last one, since it eliminates the nested maps and lists from the TOML. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. |
||
ExprLambda = { fields = [ | ||
{ name = "parameters", type = "Parameters", optional = true }, | ||
{ name = "body", type = "Expr" } | ||
]} | ||
ExprIf = { fields = [ | ||
{ name = "test", type = "Expr" }, | ||
{ name = "body", type = "Expr" }, | ||
{ name = "orelse", type = "Expr" } | ||
]} | ||
ExprDict = { fields = [ | ||
{ name = "items", type = "DictItem", seq = true }, | ||
]} | ||
|
||
[ExceptHandler] | ||
rustdoc = "/// See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler)" | ||
|
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.
Given this concern, this syntax does start to look a bit unwieldy.
But on the other hand, continuing to use TOML still makes it easier to iterate on the code generator itself.
So given all of this, I'd still lean towards using this TOML syntax. We can always revisit the syntax later if we feel there's something that e.g. ungrammar would give us that the TOML doesn't.