tree-sitter / py-tree-sitter

Python bindings to the Tree-sitter parsing library
https://tree-sitter.github.io/py-tree-sitter/
MIT License
817 stars 96 forks source link

Tree sitter gets stuck #226

Closed Moddus closed 5 months ago

Moddus commented 5 months ago

Hi,

I'm using tree-sitter to parse some scala code using the related grammar from: https://github.com/tree-sitter/tree-sitter-scala

Please find the related scala sample attached: sample.txt

Running the code in the snippet below cause the parse to get stuck in an infinite loop, I assume, even if I defined the timeout. Not sure how I could debug the issue or if it's related to tree-sitter itself or the scala grammar.

from tree_sitter import Language, Parser, Range

binary_name = "<path to binary>"
SCALA_LANGUAGE = Language(binary_name, "scala")

parser = Parser()
parser.set_timeout_micros(int(1e6))
parser.set_language(SCALA_LANGUAGE)

with open("sample.txt") as fp:
    scala_code = fp.read()

parser.parse(bytes(scala_code, "utf8"))  # program gets stuck

Thanks for you time and suggestions

ObserverOfTime commented 5 months ago

You can check if it's related to tree-sitter itself or the scala grammar by renaming sample.txt to sample.scala and running tree-sitter parse sample.scala --timeout 1000000 in the tree-sitter-scala folder.

ObserverOfTime commented 5 months ago

Which does hang so this is (most likely) an issue with the grammar or (less likely) with tree-sitter.

Moddus commented 5 months ago

@ObserverOfTime thanks for the insides much appreciated!