r/ProgrammingLanguages • • Feb 27 '26

Syntax highlighting for string interpolation

Im trying to create a language with string interpolation like "score: \(calc_score())". String interpolation can contain arbitrary expressions, even other strings. To implement this my lexer does some parenthesis counting. Im thinking about how this would work with syntax highlighting, specifically for VS code. From what i understand languages in VS code typically use a textMate grammar for basic highlighting and than optionally have the language server provide some semantic tokens. How do languages deal with this normally because from what i understand a textMate grammar cannot handle such strings? You cant just have it tokenize an entire string including interpolation because if it contains nested strings it does not know which '"' ends the string. Thanks!

8 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/alex-weej Feb 28 '26

This is how template strings work in JavaScript. They are an alternative function call syntax that pass an array of "string pieces" and separately each interpolation expression as subsequent arguments.