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

Special case not managed by the parser, when an expression is split without a backslash and the second line is dedented. #179

Closed
martinett opened this issue Dec 1, 2023 · 4 comments

Comments

@martinett
Copy link

Here is a minimal valid python code sample for the parser to detect an error :

if True:
    l[i+
1]

And here is a minimal code to get the error :

from tree_sitter import Language, Parser

Language.build_library("build/my-languages.so", ["parsers/tree-sitter-python"])
PY_LANGUAGE = Language("build/my-languages.so", "python")
parser = Parser()
parser.set_language(PY_LANGUAGE)

code = "if True:\n    l[i+\n1]"
tree = parser.parse(bytes(code,"utf-8"))
print(tree.root_node.sexp())
print(tree.root_node.children[1])
print(tree.root_node.children[0].children[3])
(module (if_statement condition: (true) (ERROR (identifier) (identifier)) consequence: (block)) (ERROR (integer)))
<Node type=ERROR, start_point=(2, 0), end_point=(2, 2)>
<Node type=ERROR, start_point=(1, 4), end_point=(1, 8)>

Whatever the indentation of the 1] line, if it is less indented than the l[i+ line, the parser detects an error.
But this code is valid, it works and the ast library has no problem parsing it.

@martinett
Copy link
Author

I don't think it is a parser python version problem, but I couldn't find how to check this.

@ObserverOfTime
Copy link
Member

That seems like a parser issue, if still relevant.

@ObserverOfTime ObserverOfTime closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2024
@martinett
Copy link
Author

So there is no solution to this? I can't deal with codes which contain this pattern.

@amaanq
Copy link
Member

amaanq commented Feb 26, 2024

it is a parser error, feel free to PR a fix yourself in the parser repo

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

3 participants