I am creating a syntax definition for the Stata language, and I’m having trouble getting the scopes right for a certain kind of embedded strings. Stata can enclose strings with double-quotes; it can also enclose string with so-called compound double quotes, which are opened with `" (backtick-double-quote) and closed with "’ (doublequote-apostrophe). Compound-double-quoted string can include double-quoted string. I want them colored differently, and I want double-quoted strings that are within compound-double-quoted string to take the color of double-quoted string.
I can scope them just fine with this:
double-quote:
- match: (?<!`)"(?!')
scope: punctuation.definition.string.begin.double.stata
push:
- meta_scope: string.quoted.double.stata
- match: (?<!`)"(?!')
scope: punctuation.definition.string.end.double.stata
pop: true
compound-quote:
- match: '`"'
scope: punctuation.definition.string.begin.double.compound.stata
push:
- meta_scope: string.quoted.double.compound.stata
- match: '"'''
scope: punctuation.definition.string.end.double.compound.stata
pop: true
- include: compound-quote
- include: double-quote
And everything works with the syntax highlighting:
But there are cases where a compound-double-quoted string can contain an unmatched double-quote character, like this:
`" This string " has an unmatched double-quotation mark"'
But this doesn’t get highlighted right, because the compound closing is not recognized:
So, I’d like to handle this one of two ways:
-
Ideally, the double-quote within a compound quote will only trigger the double-quote scope if there is a matching double-quote to end the double-quote scope
-
Less ideally, the
"'
that pops the compound-double-quote scope should also pop any added double-quote scope as well.
Any thoughts or advice?
Thanks!!!