Skip to content

Commit 46963ea

Browse files
authored
Add string interpolation highlighting (#24)
Add string interpolation highlighting
2 parents 3028052 + 6453d96 commit 46963ea

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
"use strict";
22
import { TmLanguage } from "./TMLanguageModel";
33

4+
const letter = "[_a-zA-Z\\$\\p{Lo}\\p{Lt}\\p{Nl}\\p{Ll}\\p{Lu}]"
5+
const digit = "[0-9]"
6+
const letterOrDigit = `${letter}|${digit}`
7+
const alphaId = `${letter}+`
8+
const simpleInterpolatedVariable = `${letter}(?:${letterOrDigit})*` // see SIP-11 https://docs.scala-lang.org/sips/string-interpolation.html
9+
410
export const scalaTmLanguage: TmLanguage = {
511
fileTypes: [
612
'scala'
@@ -217,6 +223,36 @@ export const scalaTmLanguage: TmLanguage = {
217223
},
218224
name: 'string.quoted.triple.scala'
219225
},
226+
{
227+
begin: `\\b(${alphaId})(""")`,
228+
end: '"""(?!")',
229+
beginCaptures: {
230+
'1': {
231+
name: 'keyword.interpolation.scala'
232+
},
233+
'2': {
234+
name: 'string.quoted.triple.interpolated.scala punctuation.definition.string.begin.scala'
235+
}
236+
},
237+
patterns: [
238+
{
239+
"include": "#string-interpolation"
240+
},
241+
{
242+
match: '\\\\\\\\|\\\\u[0-9A-Fa-f]{4}',
243+
name: 'constant.character.escape.scala'
244+
},
245+
{
246+
match: '.',
247+
name: 'string.quoted.triple.interpolated.scala'
248+
}
249+
],
250+
endCaptures: {
251+
'0': {
252+
name: 'string.quoted.triple.interpolated.scala punctuation.definition.string.end.scala'
253+
}
254+
}
255+
},
220256
{
221257
end: '"',
222258
begin: '"',
@@ -241,6 +277,68 @@ export const scalaTmLanguage: TmLanguage = {
241277
}
242278
},
243279
name: 'string.quoted.double.scala'
280+
},
281+
{
282+
begin: `\\b(${alphaId})(")`,
283+
end: '"',
284+
beginCaptures: {
285+
'1': {
286+
name: 'keyword.interpolation.scala'
287+
},
288+
'2': {
289+
name: 'string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala'
290+
}
291+
},
292+
patterns: [
293+
{
294+
include: "#string-interpolation"
295+
},
296+
{
297+
match: `\\\\(?:[btnfr\\\\"']|[0-7]{1,3}|u[0-9A-Fa-f]{4})`,
298+
name: 'constant.character.escape.scala'
299+
},
300+
{
301+
match: '\\\\.',
302+
name: 'invalid.illegal.unrecognized-string-escape.scala'
303+
},
304+
{
305+
match: '.',
306+
name: 'string.quoted.double.interpolated.scala'
307+
}
308+
],
309+
endCaptures: {
310+
'0': {
311+
name: 'string.quoted.double.interpolated.scala punctuation.definition.string.end.scala'
312+
}
313+
}
314+
}
315+
]
316+
},
317+
'string-interpolation': {
318+
patterns: [
319+
{
320+
name: "constant.character.escape.interpolation.scala",
321+
match: "\\$\\$"
322+
},
323+
{
324+
match: `(\\$)(${simpleInterpolatedVariable})`,
325+
captures: {
326+
"1": {
327+
name: "punctuation.definition.template-expression.begin.scala"
328+
}
329+
}
330+
},
331+
{
332+
name: "punctuation.definition.template-expression.scala",
333+
begin: "\\$\\{",
334+
beginCaptures: { "0": { name: "punctuation.definition.template-expression.begin.scala" } },
335+
end: "\\}",
336+
endCaptures: { "0": { name: "punctuation.definition.template-expression.end.scala" } },
337+
patterns: [
338+
{
339+
include: "#code"
340+
}
341+
]
244342
}
245343
]
246344
},

0 commit comments

Comments
 (0)