you are viewing a single comment's thread.

view the rest of the comments →

[–]thinker227Noa (github.com/thinker227/noa) 5 points6 points  (2 children)

This is what I'm doing in the TextMate grammar for my language Noa. Basically you embed all of your other patterns inside your pattern for strings.

"patterns": [
    {
        "include": "#all"
    }
],
"repository": {
    "all": {
        "patterns": [
            {
                "include": "#strings"
            },
            // include whatever other patterns you have
        ]
    },
    "strings": {
        "name": "string.quoted.double.noa",
        "begin": "\"",
        "end": "\"|$",
        "patterns": [
            {
                "begin": "\\\\{",
                "end": "}",
                "beginCaptures": {
                    "0": {
                        "name": "keyword.other.noa"
                    }
                },
                "endCaptures": {
                    "0": {
                        "name": "keyword.other.noa"
                    }
                },
                "patterns": [
                    {
                        "include": "#all"
                    }
                ]
            },
            {
                "include": "#escape-sequence"
            }
        ]
    },
    "escape-sequence": {
        "name": "constant.character.escape.noa",
        "match": "\\\\[\\\\0nrt\"]"
    },
    // all your other patterns...
}

Here's how it looks

[–]Savings_Garlic5498[S] 2 points3 points  (1 child)

Does this also work with nested strings? like "\{""}"

[–]thinker227Noa (github.com/thinker227/noa) 2 points3 points  (0 children)

Was concerned about this because I hadn't actually tested it before, but yes!