virchau13 / tree-sitter-astro

Tree-sitter grammar for the Astro web framework
MIT License
98 stars 9 forks source link

Parser doesn't work if 3 or more hyphens in front matter #25

Closed jamesrayman closed 7 months ago

jamesrayman commented 8 months ago

Here's an example in the form of a tree-sitter test:

====================
Three hyphens in frontmatter
====================

---
const myArray = [-1, -2, -3]
---

<h1>Hello world!</h1>

--------------------

(document
  (frontmatter
    (raw_text))
  (element
    (start_tag
      (tag_name))
    (text)
    (end_tag
      (tag_name))))

Here is the test output:

1 failure:

correct / - expected / + unexpected

  1. Three hyphens in frontmatter:

    (document
+     (ERROR
+       (raw_text)
+       (UNEXPECTED '3'))
-     (frontmatter
-       (raw_text))
      (element
        (start_tag
          (tag_name))
        (text)
        (end_tag
          (tag_name))))

If you make one of the numbers in myArray positive, the test passes. I'm pretty sure the bug sits somewhere in scan_js_expr in src/scanner.c.

KeentGG commented 7 months ago

No updates on this yet?

I just spent half a day trying to debug this, i am new at Neovim and wasn't sure if my config was not working. Found out this was an issue with the astro tree sitter itself.

Hope this can be fixed as this is a major block for me to use Astro on nvim or vice versa.

jamesrayman commented 7 months ago

Feel free to open a pull request yourself. Otherwise, you'll have to wait for me or someone else to decide it's worth our time to fix. If you need a quick and dirty fix in the meantime, comments reset the hyphen count. For example, the following is highlighted correctly:

---
const myArray = [-1, -2, /* */ -3]
---
KeentGG commented 7 months ago

Alright thanks for the tip!

Sorry wasn't meant to put pressure but was just asking in general if someone has update or found a solution. Glad you found a workaround for the meantime.

virchau13 commented 7 months ago

Sorry for the wait. Fixed in ccd8826973bdd770136481e96554ee7c570f0fd4.