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

Python parsing does not work well with empty blocks #64

Closed
mgsloan opened this issue May 1, 2020 · 2 comments · Fixed by #65
Closed

Python parsing does not work well with empty blocks #64

mgsloan opened this issue May 1, 2020 · 2 comments · Fixed by #65

Comments

@mgsloan
Copy link

mgsloan commented May 1, 2020

In the playground, if I type in

def foo():

I get

module [0, 0] - [1, 0])
  ERROR [0, 0] - [0, 10])
    identifier [0, 4] - [0, 7])
    parameters [0, 7] - [0, 9])

If I add a statement at indent level 0:

def foo():

print "hi"

I get

module [0, 0] - [3, 0])
  function_definition [0, 0] - [2, 10])
    name: identifier [0, 4] - [0, 7])
    parameters: parameters [0, 7] - [0, 9])
    body: block [2, 0] - [2, 10])
      print_statement [2, 0] - [2, 10])
        argument: string [2, 6] - [2, 10])

I believe this reveals a flaw in the indentation sensitivity of the python parser. Ideally:

  1. print "hi" should not get parsed as a child of the function_definition.

  2. The empty block should be filled in with a MISSING recovery of insertion of pass

I don't know much about tree sitter grammar construction, so I am not sure if fixing this is feasible. Similar issues occur with unterminated parenthesis at the end of the block, incomplete infix operators, etc.

@maxbrunsfeld
Copy link
Contributor

Thanks for writing this up!

@mgsloan
Copy link
Author

mgsloan commented May 1, 2020

You're welcome, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants