Hey, there! I’m a syntax definition noob trying to understand scopes and popping. My goal is to write a syntax definition that supports embedding HTML inside of JS, like JSX, but specifically for HTML template strings (see nanohtml). Here’s an example of what the language looks like:
script.js
// This is normal javascript
const myFunction = () => {
return html`
<!-- This is HTML -->
<div>Look ma! Just plain ol' HTML. ${ 'And this should be the embedded_js scope' }</div>
<div>Weirdly, when I ctrl+alt+shift+P here, I'm still in the embedded_js scope. It hasn't popped. Any idea why?</div>
`
}
And here’s my attempt at a syntax definition:
%YAML 1.2
---
file_extensions:
- js
scope: source.nanohtml
contexts:
main:
- match: ''
push: 'scope:source.js'
with_prototype:
- match: html\`
push: "Packages/HTML/HTML.sublime-syntax"
with_prototype:
- match: \`
pop: true
- match: \$\{
push: embedded_js
embedded_js:
- meta_content_scope: source.nanohtml.embedded_js
- match: \}
pop: true
- include: 'scope:source.nanohtml'
For some reason, my pop
in embedded_js
doesn’t seem to be working. When I ctrl+alt+shift+P
in a line following ${ }
, I’m still in the embedded_js context. Any idea why?