Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Support literal interpolated strings ($@"") #13

Merged
merged 2 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,12 @@ export var language = <ILanguage> {
// delimiters and operators
[/}/, { cases: {
'$S2==interpolatedstring' : { token: 'string.quote', next: '@pop' }
, '$S2==litinterpstring' : { token: 'string.quote', next: '@pop' }
, '@default' : '@brackets' } }],
[/[{}()\[\]]/, '@brackets'],
[/[<>](?!@symbols)/, '@brackets'],
[/@symbols/, { cases: { '@operators': 'delimiter', '@default' : '' } } ],

// literal string
[/\@"/, { token: 'string.quote', next: '@litstring' } ],

// interpolated string
[/\$"/, { token: 'string.quote', next: '@interpolatedstring' } ],

// numbers
[/\d*\.\d+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'],
Expand All @@ -112,6 +108,9 @@ export var language = <ILanguage> {
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
[/"/, { token: 'string.quote', next: '@string' } ],
[/\$\@"/, { token: 'string.quote', next: '@litinterpstring' } ],
[/\@"/, { token: 'string.quote', next: '@litstring' } ],
[/\$"/, { token: 'string.quote', next: '@interpolatedstring' } ],

// characters
[/'[^\\']'/, 'string'],
Expand Down Expand Up @@ -155,6 +154,15 @@ export var language = <ILanguage> {
[/"/, { token: 'string.quote', next: '@pop' } ]
],

litinterpstring: [
[/[^"{]+/, 'string'],
[/""/, 'string.escape'],
[/{{/, 'string.escape'],
[/}}/, 'string.escape'],
[/{/, { token: 'string.quote', next: 'root.litinterpstring' } ],
[/"/, { token: 'string.quote', next: '@pop' } ]
],

interpolatedstring: [
[/[^\\"{]+/, 'string'],
[/@escapes/, 'string.escape'],
Expand All @@ -173,4 +181,4 @@ export var language = <ILanguage> {
[/\/\/.*$/, 'comment'],
],
},
};
};
23 changes: 22 additions & 1 deletion test/csharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,5 +740,26 @@ testTokenization('csharp', [
{ startIndex: 0, type: 'string.cs' },
{ startIndex: 6, type: 'string.quote.cs' },
{ startIndex: 7, type: 'delimiter.cs' }
]}]
]}],

[{
line: 'x = $@"verbatim {interpolated} string{{}}"" ";',
tokens: [
{ startIndex: 0, type: "identifier.cs" },
{ startIndex: 1, type: "" },
{ startIndex: 2, type: "delimiter.cs" },
{ startIndex: 3, type: "" },
{ startIndex: 4, type: "string.quote.cs" },
{ startIndex: 7, type: "string.cs" },
{ startIndex: 16, type: "string.quote.cs" },
{ startIndex: 17, type: "identifier.cs" },
{ startIndex: 29, type: "string.quote.cs" },
{ startIndex: 30, type: "string.cs" },
{ startIndex: 37, type: "string.escape.cs" },
{ startIndex: 39, type: "string.cs" },
{ startIndex: 41, type: "string.escape.cs" },
{ startIndex: 43, type: "string.cs" },
{ startIndex: 44, type: "string.quote.cs" },
{ startIndex: 45, type: "delimiter.cs" },
]}],
]);