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

tree-sitter-python parses file with errors, but tree has no errors #108

Open
eaftan opened this issue Jun 7, 2021 · 2 comments
Open

tree-sitter-python parses file with errors, but tree has no errors #108

eaftan opened this issue Jun 7, 2021 · 2 comments

Comments

@eaftan
Copy link

eaftan commented Jun 7, 2021

I would expect this not to parse/parse with errors:

def foo():
foo()

But AFAICT there are no ERROR nodes in the tree, nor are there any nodes for which hasError() returns true. It looks like this was intentionally added in #65 ("As is often the case, I think the most practical fix is to allow a superset of what Python really allows, and treat empty blocks as valid blocks.")

I have a higher-level question: if I want to know whether a file parses correctly, can I do that with tree-sitter? Or is that not what tree-sitter is for?

@maxbrunsfeld
Copy link
Contributor

You can check if a block is empty by looking at its children in the syntax tree. So if you wanted to add some special handling for empty blocks (like an error message that says "Blocks must contain one or more statement"), you could do that by checking if a block contains any statements.

@eaftan
Copy link
Author

eaftan commented Jun 7, 2021

Thanks @maxbrunsfeld. Is it generally true that tree-sitter accepts a superset of what the programming language grammar allows? I'm trying to understand what to expect from tree-sitter, rather than trying to deal with this specific issue.

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

No branches or pull requests

2 participants