Highlight subexpression on string

Hi there,

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).


Thanks for your reply it has been useful but still missing the key, but the thing is improving though.
Now I’ve have this:


It respects the highlighting style of the custom expression but now I don’t have either the property name nor the value stylized.

I think it will be faster to understand where I’m doing wrong if I share the grammar file:

After many iterations and tests I’ve ended up deleting the @local token declaration because I couldn’t manage to get it working.

The only additions to basic JSON grammar file really are the BinnaryExpression declaration (line 31) and the second @skip expression (line 36)

Thanks so much for your time, the system behind the library is so huge and complex!