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

Fix parsing UTF-16 files #252

Closed
tamasvajk opened this issue Dec 20, 2022 · 2 comments
Closed

Fix parsing UTF-16 files #252

tamasvajk opened this issue Dec 20, 2022 · 2 comments

Comments

@tamasvajk
Copy link
Collaborator

Files with UTF-16 LE or BE encoding produce error nodes. Empty file saved with UTF-16 BE encoding in VS Code produces the below:

❯ tree-sitter parse a.cs
(compilation_unit [0, 0] - [0, 2]
  (ERROR [0, 0] - [0, 2]
    (ERROR [0, 0] - [0, 2])))
a.cs    0 ms    (ERROR [0, 0] - [0, 2])

The same file with UTF-8 encoding:

❯ tree-sitter parse a.cs
(compilation_unit [0, 0] - [0, 0])
@damieng
Copy link
Contributor

damieng commented Dec 20, 2022

There isn't anything in the grammar that is specifically UTF-8 and we're using tree-sitter ^0.20.0 so I'm not sure what needs to be done here - I checked a couple of the other repos but didn't see anything about UTF-16 there either. I would have expected tree-sitter itself to take care of that as it reads the file.

@tamasvajk
Copy link
Collaborator Author

Sorry for the noise, I think this issue can be closed. I think the CLI is calling parse, which has a comment Parse a slice of UTF8 text., which explains why this happens. The documentation details TSInput, which does have an encoding.

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

2 participants