elixir-lang / tree-sitter-elixir

Elixir grammar for tree-sitter
https://elixir-lang.org/tree-sitter-elixir
Apache License 2.0
249 stars 25 forks source link

escape_sequence and regex #64

Closed fictorial closed 8 months ago

fictorial commented 8 months ago

This is a valid js regex yet tree-sitter doesn't care for it. Any ideas?

Error processing rule escape_sequence

Caused by:
    regex parse error:
        u{[0-9a-fA-F]+}
          ^
    error: repetition quantifier expects a valid decimal
$ tree-sitter --version
tree-sitter 0.22.2 (fc15f621334a262039ffaded5937e2844f88da61)
jonatanklosko commented 8 months ago

Can you provide a minimal regex/snippet that causes the error?

jonatanklosko commented 8 months ago

Oh, this is the JS from the grammar itself, did it start failing when you updated the TS version?

fictorial commented 8 months ago

Thanks for getting back to me so quickly. It's happening with Dart and R as well. This is the first I've used TS so there has not been an upgrade.

fictorial commented 8 months ago
$ cd /tmp
$ git clone https://github.com/elixir-lang/tree-sitter-elixir --depth=1
Cloning into 'tree-sitter-elixir'...
remote: Enumerating objects: 100, done.
remote: Counting objects: 100% (100/100), done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 100 (delta 20), reused 48 (delta 5), pack-reused 0
Receiving objects: 100% (100/100), 589.04 KiB | 1.43 MiB/s, done.
Resolving deltas: 100% (20/20), done.
$ cd tree-sitter-elixir
$ tree-sitter generate
Error processing rule escape_sequence

Caused by:
    regex parse error:
        x{[0-9a-fA-F]+}
          ^
    error: repetition quantifier expects a valid decimal
$ tree-sitter --version
tree-sitter 0.22.2 (fc15f621334a262039ffaded5937e2844f88da61)
jonatanklosko commented 8 months ago

Ahh I see. You have tree-sitter installed globally and you are re-generating the grammar with that global version. You generally shouldn't need to generate the grammar, the generated version is a part of the repo (in our case automatically done on CI).

Is there a reason you need to generate explicitly?

jonatanklosko commented 8 months ago

I see the official packages still use the older version of tree-sitter-cli, so I am hesitant to upgrade until it's more adopted.

jonatanklosko commented 8 months ago

As for the specific error, I think we need to escape the curly brace in the regexp. TS compiles regexps and perhaps that logic changed to be more strict.

With that you should be able to build with newer tree-sitter.

fictorial commented 8 months ago

I'm creating a single TS Library containing about 45 languages/parsers by cloning the repos and generating the grammars, then building the TS Library.

OK, so it's just a latest-version issue. I tried older versions and it started working at 0.20.8.

$ cd /tmp
$ git clone https://github.com/elixir-lang/tree-sitter-elixir --depth=1
$ cd tree-sitter-elixir
$ npx tree-sitter@0.20.8 generate

Thanks!

jonatanklosko commented 8 months ago

FWIW here is a list of dependencies used in the Zed editor.