Skip to content
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

[New] Handle Boolop operands similar to CPython AST #773

Merged
merged 2 commits into from Jul 17, 2022

Conversation

Thirumalai-Shaktivel
Copy link
Collaborator

@Thirumalai-Shaktivel Thirumalai-Shaktivel commented Jul 16, 2022

This PR is about handling the Boolop operands.
For example:

a or b or z

should be printed as (this PR):

lpython --show-ast examples/expr2.py --tree --new-parser
└-Module
  |-body=↧
  | └-Expr
  |   └-value=BoolOp
  |     |-boolopType=Or
  |     └-values=↧
  |       |-Name
  |       | |-id=a
  |       | └-expr_contextType=Load
  |       |-Name
  |       | |-id=b
  |       | └-expr_contextType=Load
  |       └-Name
  |         |-id=z
  |         └-expr_contextType=Load
  └-type_ignores=↧

not (previously):

$ lpython --show-ast examples/expr2.py --tree --new-parser
└-Module
  |-body=↧
  | └-Expr
  |   └-value=BoolOp
  |     |-boolopType=Or
  |     └-values=↧
  |       |-Name
  |       | |-id=a
  |       | └-expr_contextType=Load
  |       └-BoolOp
  |         |-boolopType=Or
  |         └-values=↧
  |           |-Name
  |           | |-id=b
  |           | └-expr_contextType=Load
  |           └-Name
  |             |-id=z
  |             └-expr_contextType=Load
  └-type_ignores=↧

@Thirumalai-Shaktivel Thirumalai-Shaktivel added the Parser Issues or improvements related to parser label Jul 16, 2022
(a and (b and (c or d)) and (e and f) or x) and y

# # TODO: Make this work similar to Old Parser
# (a or b and c) or z
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(a or b) or c

The problem here is that, as parenthesis information is not used or stored by the macros, it is difficult to handle the above example:
OLD Parser AST:

$ lpython --show-ast examples/expr2.py --tree
└-Module
  |-body=↧
  | └-Expr
  |   └-value=BoolOp
  |     |-boolopType=Or
  |     └-values=↧
  |       |-BoolOp
  |       | |-boolopType=Or
  |       | └-values=↧
  |       |   |-Name
  |       |   | |-id=a
  |       |   | └-expr_contextType=Load
  |       |   └-Name
  |       |     |-id=b
  |       |     └-expr_contextType=Load
  |       └-Name
  |         |-id=c
  |         └-expr_contextType=Load
  └-type_ignores=↧

NEW Parser AST (this PR):

$ lpython --show-ast examples/expr2.py --tree --new-parser
└-Module
  |-body=↧
  | └-Expr
  |   └-value=BoolOp
  |     |-boolopType=Or
  |     └-values=↧
  |       |-Name
  |       | |-id=a
  |       | └-expr_contextType=Load
  |       |-Name
  |       | |-id=b
  |       | └-expr_contextType=Load
  |       └-Name
  |         |-id=c
  |         └-expr_contextType=Load
  └-type_ignores=↧

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvements.

@Thirumalai-Shaktivel
Copy link
Collaborator Author

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Parser Issues or improvements related to parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants