py-tree-sitter icon indicating copy to clipboard operation
py-tree-sitter copied to clipboard

Parser.parse does not accept a "read_callable" function

Open MatthieuDien opened this issue 3 years ago • 1 comments

Hello,

Firstly, thank you a lot for your work ! I tried to use tree-sitter to make a text editor for graphviz language with real time graphic rendering. I tried to copy-paste the examples given in the README but it seems there is a bug.

I obtain the following error in the case I give a read_callable to Parser.parse instead of a bytes:

src = bytes(""" 
    def foo(): 
        if bar: 
            baz() 
    """, "utf8") 
def read_callable(byte_offset, point): 
    return src[byte_offset:byte_offset+1]
tree = parser.parse(read_callable)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-7e3e4d2774eb> in <module>
      8     return src[byte_offset:byte_offset+1]
      9 
---> 10 tree = parser.parse(read_callable)

TypeError: First argument to parse must be bytes

For the example I used the python language (as in the README). Did I forgot something ? I use IPython 7.13.0 with Python 3.8.10.

MatthieuDien avatar Feb 21 '22 09:02 MatthieuDien

This feature was only merged 6 days ago in #55 / 55abe1c2702d038d4851422a293feb5b1f08ccdb, and there has not been a PyPI release since then. You can try installing from git with pip install git+https://github.com/tree-sitter/py-tree-sitter until there is a new release.

narpfel avatar Feb 23 '22 17:02 narpfel