tree-sitter / haskell-tree-sitter

Haskell bindings for tree-sitter
152 stars 45 forks source link

`ts_parser_parse_string` seems to hang when the parsing fails #303

Open balsoft opened 2 years ago

balsoft commented 2 years ago

With GHC 9.0.2, ts_parser_parse_string seems to hang if the parsing fails. Reproduce:

❯ ghci
GHCi, version 9.0.2: https://www.haskell.org/ghc/  :? for help
ghci> import Foreign
ghci> import TreeSitter.Haskell
ghci> import TreeSitter.Parser
ghci> import TreeSitter.Tree
ghci> import Foreign.C
ghci> parser <- ts_parser_new
ghci> _ <- ts_parser_set_language parser tree_sitter_haskell
ghci> (str, len) <- newCStringLen "this hangs everything"
ghci> tree <- ts_parser_parse_string parser nullPtr str len -- This hangs indefinitely
^C^CInterrupted.

The same works if the string is valid tree-sitter's Haskell grammar (including an empty string).

I have tree-sitter-haskell-0.3.0.2, tree-sitter-0.9.0.3 and ghc-9.0.2. If that matters, this is NixOS Linux, and all packages are provided from nixpkgs. The exact environment can be reproduced with NIX_PATH=nixpkgs=https://github.com/nixos/nixpkgs/archive/c5924154f000e6306030300592f4282949b2db6c.tar.gz nix-shell -p 'haskellPackages.ghcWithPackages (ps: with ps; [ tree-sitter tree-sitter-haskell ])' .

I'm not sure how to debug this further.

jorpic commented 1 year ago

I don't know what is the root of the problem but tree-sitter-0.9.0.3 is really outdated and depends on a version of tree-sitter that is more than 2 years old.

I updated dependencies here and now it works without looping forever. Please see example in this gist. Or you can git clone https://gist.github.com/e60cd0cb3a14acf28b87f7e5838bcd70.git issue303 and try it.

2482411499 commented 1 year ago

docs/section-3-creating-parsers.md