Skip to content

Commit 925245c

Browse files
committed
Add string interpolation highlighting
1 parent 3028052 commit 925245c

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
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 variableName = `${letter}(?:${letterOrDigit})*`
8+
49
export const scalaTmLanguage: TmLanguage = {
510
fileTypes: [
611
'scala'
@@ -217,6 +222,36 @@ export const scalaTmLanguage: TmLanguage = {
217222
},
218223
name: 'string.quoted.triple.scala'
219224
},
225+
{
226+
begin: '\\b(s|f|raw)(""")',
227+
end: '"""(?!")',
228+
beginCaptures: {
229+
'1': {
230+
name: 'keyword.interpolation.scala'
231+
},
232+
'2': {
233+
name: 'punctuation.definition.string.begin.scala'
234+
}
235+
},
236+
patterns: [
237+
{
238+
"include": "#string-interpolation"
239+
},
240+
{
241+
match: '\\\\\\\\|\\\\u[0-9A-Fa-f]{4}',
242+
name: 'constant.character.escape.scala'
243+
},
244+
{
245+
match: '.',
246+
name: 'string.quoted.triple.interpolated.scala'
247+
}
248+
],
249+
endCaptures: {
250+
'0': {
251+
name: 'punctuation.definition.string.end.scala'
252+
}
253+
}
254+
},
220255
{
221256
end: '"',
222257
begin: '"',
@@ -241,6 +276,72 @@ export const scalaTmLanguage: TmLanguage = {
241276
}
242277
},
243278
name: 'string.quoted.double.scala'
279+
},
280+
{
281+
begin: '\\b(s|f|raw)(")',
282+
end: '"',
283+
beginCaptures: {
284+
'1': {
285+
name: 'keyword.interpolation.scala'
286+
},
287+
'2': {
288+
name: 'punctuation.definition.string.begin.scala'
289+
}
290+
},
291+
patterns: [
292+
{
293+
include: "#string-interpolation"
294+
},
295+
{
296+
match: `\\\\(?:[btnfr\\\\"']|[0-7]{1,3}|u[0-9A-Fa-f]{4})`,
297+
name: 'constant.character.escape.scala'
298+
},
299+
{
300+
match: '\\\\.',
301+
name: 'invalid.illegal.unrecognized-string-escape.scala'
302+
},
303+
{
304+
match: '.',
305+
name: 'string.quoted.double.interpolated.scala'
306+
}
307+
],
308+
endCaptures: {
309+
'0': {
310+
name: 'punctuation.definition.string.end.scala'
311+
}
312+
}
313+
}
314+
]
315+
},
316+
'string-interpolation': {
317+
patterns: [
318+
{
319+
name: "constant.character.escape.interpolation.scala",
320+
match: "\\$\\$"
321+
},
322+
{
323+
name: "constant.other.placeholder.scala",
324+
match: `(\\$)(${variableName})`,
325+
captures: {
326+
"1": {
327+
name: "punctuation.definition.template-expression.begin.scala"
328+
},
329+
"2": {
330+
name: "variable.other.scala"
331+
}
332+
}
333+
},
334+
{
335+
name: "punctuation.definition.template-expression.scala",
336+
begin: "\\$\\{",
337+
beginCaptures: { "0": { name: "punctuation.definition.template-expression.begin.scala" } },
338+
end: "\\}",
339+
endCaptures: { "0": { name: "punctuation.definition.template-expression.end.scala" } },
340+
patterns: [
341+
{
342+
include: "#code"
343+
}
344+
]
244345
}
245346
]
246347
},

0 commit comments

Comments
 (0)