How to stop TextMate Grammar from matching end tokens as start tokens when they have the same pattern

53 views Asked by At

I am currently trying highlight values between square brackets {} inside of SQL strings using a Textmate Grammar injection in vscode. This is being done through an injection grammar. (the support.class is a placeholder name)

    "repository": {
        "parameters": {
            "name": "support.class",
            "match": "\\{[^}]*\\}"}

However this isn't matching as the SQL quote character (') stops it from tokenizing the brackets. I would be able to get around this if I were to implement something like this

    "sqlQuoteInject" : {
    "name": "string.quoted.single.mtx",
    "begin" : "'",
    "end": "'",
    "patterns": [
    {
        "name": "support.class",
        "match": "\\{[^}]*\\}"
    }
   ]
}

This works to highlight everything inside the brackets but the ' end quote is for some reason being read as a begin quote. This means it is effectively impossible to end the quotations resulting in the entire document being highlighted as a quote.

The SQL grammar I am injecting to is another custom grammar that just uses "include" : [source.sql]

Eg. A file with the text

'abc' 123

Would highlight 123 as being a quote as the c' counts as the start of a quotation.

Any suggestion would be helpful.

0

There are 0 answers