Himujjal / tree-sitter-svelte

Tree sitter grammar for Svelte
MIT License
81 stars 14 forks source link

Add expressions inside string attribute values #51

Open savetheclocktower opened 9 months ago

savetheclocktower commented 9 months ago

Fixes #44.

I tried to roughly follow the design of template strings in tree-sitter-javascript. Instead of doing something like…

(attribute_value
  (value_fragment)
  (expression (raw_text_expr))
  (value_fragment)
)

…I instead did…

(attribute_value
  (expression (raw_text_expr))
)

…so if you want to identify just the literal string parts, you can take (attribute_value) and ignore/subtract its children.

savetheclocktower commented 9 months ago

By the way, I've purposefully been making atomic PRs, but I've also got a branch with all of these changes combined. If they all look good to you individually, I can open a PR against that branch and we can save ourselves some merging headaches.

Himujjal commented 6 months ago

@savetheclocktower I would love for you to make a PR for the same. It would save us time as well

AlbertMarashi commented 4 weeks ago

Much of zed's svelte issues come from the lack of support for things like this

AlbertMarashi commented 4 weeks ago

Also, are you sure about not making it like the former you shared?

Else, how will we do something like

[
  (attribute_value)
  (quoted_attribute_value)
] @string

For zed's syntax highlighting?

savetheclocktower commented 4 weeks ago

Else, how will we do something like

[
  (attribute_value)
  (quoted_attribute_value)
] @string

For zed's syntax highlighting?

I might be misunderstanding, but I don't see how this PR affects your ability to do that. The fact that all quoted_attribute_values have an inner attribute_value node is a behavior that this parser inherits from the HTML parser. It seems like your sample query would still work.

If you're saying that you want a way to identify everything but the expression so that you can highlight those parts like a string but not the expression… I imagine that could be solved by explicitly highlighting the inner expression in a non-string-like way to override the styles it would inherit from the surrounding string.