I’m trying to extend the JSON grammar because I needed it to be highlighting a custom expression that could or not be inside a string, depending on the case.
The case of use can be seen on Postman website, where they used custom variables withing strings but still can manage to highlight the custom expression for variables like so:
Actually I created a new language based on JSON syntax and added this:
BinaryExpression { “{{” @asciiLetter+ “}}”} on @tokens declaration and it works fine until I put inside string delimiters (")
I would like to know which part I’m missing because it feels a bit abstract for me, thanks in advance!
The parser will read one token at a time. If it sees a double quote, it’ll read the whole string token, up to the closing quote, including any double braces that might be in there in the string token. So what you probably need to do is split strings into multiple tokens — opening quote, followed by any number of string content tokens or variables, followed by a closing quote. You may be able to use ‘local token groups’ to define the tokens inside the string (variable, end quote, or content).