In my syntax highlighter for language A, I’m trying to add syntax highlighting for language B inside specific blocks. Since HTML can include CSS or JavaScript, I took a look at how this is done in HTML.sublime-syntax:
- match: '(?:^\s+)?(<)((?i:style))\b(?![^>]*/>)'
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.style.html
push:
- match: (?i)(</)(style)(>)
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.style.html
3: punctuation.definition.tag.end.html
pop: true
- include: tag-stuff
- match: '>'
scope: punctuation.definition.tag.end.html
push:
- meta_content_scope: source.css.embedded.html
- include: 'scope:source.css'
with_prototype:
- match: (?i)(?=</style)
pop: true
In my case, language A is nsL Assembler and language B is NSIS. nsL Assembler can not only be transpiled into NSIS, but also contain blocks of vanilla NSIS.
Example:
MessageBox("This is nsL Assembler");
#nsis
MessageBox MB_OK "This is vanilla NSIS"
#nsisend
Here’s my attempt at implementing this in a trial & error fashion:
- match: '\b(#nsis)\b'
captures:
1: keyword.other.nsl
push:
- match: '\b(#nsisend)\b'
captures:
1: keyword.other.nsl
pop: true
push:
- meta_content_scope: source.nsis.embedded.nsl
- include: 'scope:source.nsis'
with_prototype:
- match: '(?i)(?=#nsisend)'
pop: true
This results in the following error:

Can someone please help me figuring this out?