tree-sitter / tree-sitter-python

Python grammar for tree-sitter
MIT License
372 stars 138 forks source link

bug: Bad parse/behavior with docstring containing extraneous "-character #249

Closed malthe closed 9 months ago

malthe commented 10 months ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

An incorrect docstring with an extraneous quote to start with breaks some expectation, causing indentation to fail further down.

Steps To Reproduce/Bad Parse Tree

If we run the repro code example, we get the following tree:

 (class_definition class name: (identifier) :
  body: 
   (block
    (expression_statement
     (string (string_start) (string_content) (string_end)))
    (if_statement if condition: (true) : (block))
    (expression_statement
     (call function: (identifier)
      arguments: (argument_list ( ))))))

Expected Behavior/Parse Tree

I expect that the print() statement can be correctly indented – actually, there should be exactly one possible indentation here which is one further right compared to if True.

Repro

class Hello:
    """"Oh my, was that four quotes?"""

    if True:
    print()  # <- this won't indent
amaanq commented 9 months ago

Indents aren't handled here, they're likely handled by whatever editor you use. Check in with them, because that indents fine for me in Neovim