-
Notifications
You must be signed in to change notification settings - Fork 25
Add Generator Expr support #232
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
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Hey @xmnlab
The source is the data type of the conditions key i am using in the get_structs methodIf I convert the data type to List the pre-commit tests will pass but the nodes for conditions get lost in the image representation.I was hoping if you could provide some insight on this |
3836911
to
7c3f8b8
Compare
I figured it out, is there anything left in this PR before merge into main |
], | ||
) | ||
generated_code = transpiler.visit(gen_expr) | ||
expected_code = "(x for (x + x) in range(10) if (x > 3) if (x < 7))" |
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.
maybe I didn't understand it .. but it seems it has an incorrect python syntax:
>>> (x for (x + x) in range(10) if (x > 3) if (x < 7))
File "<stdin>", line 1
(x for (x + x) in range(10) if (x > 3) if (x < 7))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: expected 'else' after 'if' expression
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.
instead of using transpiler.visit, please use translate
(e.g. https://github.com/arxlang/astx/pull/232/files#diff-213fa69c2a6fc65240961486159b29cc98cffaab2968b96afbae37a47abc4624R52)
it uses the translate.visit + a function to check if the syntax is correct
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.
done
) | ||
|
||
generated_code = transpiler.visit(gen_expr) | ||
expected_code = "(x for (x + x) in range(10))" |
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.
it is not a valid python syntax:
>>> (x for (x + x) in range(10))
File "<stdin>", line 1
(x for (x + x) in range(10))
^^^^^
SyntaxError: cannot assign to expression
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.
instead of using transpiler.visit, please use translate
(e.g. https://github.com/arxlang/astx/pull/232/files#diff-213fa69c2a6fc65240961486159b29cc98cffaab2968b96afbae37a47abc4624R52)
it uses the translate.visit + a function to check if the syntax is correct
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.
yeah I fixed the bug.
230055c
to
3ed3171
Compare
@Zehen-249 this is the current graph representation in image format |
as you can see in the image above, the "conditions" is not properly implemented. instead of list of expr it should be a astnodes of ifexpr https://github.com/arxlang/astx/blob/main/libs/astx/src/astx/classes.py#L39 https://github.com/arxlang/astx/blob/main/libs/astx/src/astx/classes.py#L52 https://github.com/arxlang/astx/blob/main/libs/astx/src/astx/classes.py#L74 so basically in the class you will set the type as ASTNodes .. in the init you should accept both ASTNodes and Iterable .. and if it is an iterable you need to convert it to astnodes in this way, in the get_struct, the conditions can be easily prepared such as any other AST node. let me know if you have any question |
please, after you fix the issue share in a new comment the graph representation in image and ascii format .. so it is easier to give you feedback |
if I use ASTNodes[IfExpr] the the transpiler for IfExpr generates 'pass if (x > 2) else None' something like this (here block node is empty if I append Variable x in it then it becomes 'x if (x > 2) else None' This can be avoid if conditions are just ASTNodes[Expr] type. |
Changed the type for conditions to ASTNodes[Expr] Object
ASCII RepresentationImage Representationtranspiller output
String Representation
|
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.
LGTM!! thanks for working on that @Zehen-249 !
🎉 This PR is included in version 0.21.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Pull Request description
Add Generator Expression Supports
Solve #199
Pull Request checklists
Note:
proposed in this PR, in both image and ASCII formats. For more
information, check this Google Colab notebook:
https://colab.research.google.com/drive/1xXwHmOMkJKFSmhRvn4WYfSAsdDzMnawf?usp=sharing
This PR is a:
About this PR:
Author's checklist:
complexity.
Additional information
Generator Expr Object Image representation
String Representation
Reviewer's checklist
Copy and paste this template for your review's note: