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

Support for nested grammars in tagged template literals #3

Closed
justinfagnani opened this issue Oct 9, 2020 · 2 comments
Closed

Support for nested grammars in tagged template literals #3

justinfagnani opened this issue Oct 9, 2020 · 2 comments

Comments

@justinfagnani
Copy link

Tagged template literals are often used to embed another language in JavaScript. It'd be nice if this grammar had built-in support for delegating to another grammar based on the template tag, ie you can register grammars against template tag identifiers, like html, css, svg, json, etc. Some editors allow registering against regexes that match the tag.

One complication is the expressions in template literals. A nested grammar should be able to parse the joined template literal strings as one character stream.

A stack of nested grammars and documents will be necessary for complex nesting. It's not uncommon to see structures like this:

html`
  <style>
    p { color: red; }
  </style>
  <div>${x ? html`<p>X</p>` : html`<p>Y</p>`</div>
  <script>...</script>
`
@marijnh
Copy link
Contributor

marijnh commented Aug 11, 2021

This should be one of the use cases unblocked by Lezer 0.15. See parseMixed.

@marijnh
Copy link
Contributor

marijnh commented Apr 23, 2024

This is now possible via a custom mixed parser wrapper.

@marijnh marijnh closed this as completed Apr 23, 2024
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