Hello,
I’m writing a syntax definition for a language which uses PCRE regular expressions for substring extraction and boolean testing. The regexes are always wrapped in hashes i.e. #<regex_here>#. Example:
foo = "Test String";
if (foo ~ #[tT]est#)
success();
if (foo ~ #\##)
// hashes inside the regex are escaped
My current solution works OK:
- match: '(?<!^)(#)(.*)(?<!\\)(#)' # first lookbehind avoids shebang (#!/bin/lang)
captures:
1: string.regexp.begin.myLanguage
2: string.regexp.myLanguage
3: string.regexp.end.myLanguage
But I would love to use Sublime Text’s own PCRE syntax highlighter in these regexes. My attempt to add RegExp.sublime-syntax, using the same match regexes, is broken:
- match: '(?<!^)#'
push: "Packages/Regular Expressions/RegExp.sublime-syntax"
with_prototype:
- match: '(?<!\\)#'
clear_scopes: true
pop: true
It successfully matches the first #, and starts highlighting using RegExp.sublime-syntax. But it doesn’t revert to the original language when it hits the final #.
For some reason, adding two hashes in a row makes it stop:
test ~~ #.*/([^/]*)#; <fails: highlights next line as if it was a regex
test ~~ #.*/([^/]*)#; ## <reverts after the two hashes
What am I doing wrong?
Your advice appreciated!
Cheers,
nwh