Skip to content

[Parser] Expressions containing in are not parsed properly (new parser) #780

Closed

Description

@akshanshbhatt
❯ cat examples/expr2.py
def has(a, b):
    return a in b

❯ lpy --show-ast examples/expr2.py --tree  # Old Parser
└-Module
  |-body=↧
  | └-FunctionDef
  |   |-name=has
  |   |-args=
  |   | |-posonlyargs=↧
  |   | |-args=↧
  |   | | |-
  |   | | | |-arg=a
  |   | | | |-annotation=()
  |   | | | └-type_comment=()
  |   | | └-
  |   | |   |-arg=b
  |   | |   |-annotation=()
  |   | |   └-type_comment=()
  |   | |-vararg=↧
  |   | |-kwonlyargs=↧
  |   | |-kw_defaults=↧
  |   | |-kwarg=↧
  |   | └-defaults=↧
  |   |-body=↧
  |   | └-Return
  |   |   └-value=Compare
  |   |     |-left=Name
  |   |     | |-id=a
  |   |     | └-expr_contextType=Load
  |   |     |-cmpopType=In
  |   |     └-comparators=↧
  |   |       └-Name
  |   |         |-id=b
  |   |         └-expr_contextType=Load
  |   |-decorator_list=↧
  |   |-returns=()
  |   └-type_comment=()
  └-type_ignores=↧

❯ lpy --show-ast --new-parser examples/expr2.py --tree  # New Parser
syntax error: Token 'in' is unexpected here
 --> examples/expr2.py:2:14
  |
2 |     return a in b
  |              ^^


Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed).

Activity

  1. krshrimali commented on Jul 18, 2022

    @krshrimali
    Contributor

    Hi, @akshanshbhatt - Thanks for raising this issue. Would you mind if I take a stab at it? (if you haven't started working on it already) :)

  2. akshanshbhatt commented on Jul 18, 2022

    @akshanshbhatt
    CollaboratorAuthor

    Yeah, sure! You can work on it. PR #709 might help you get some insight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ParserIssues or improvements related to parser

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions