Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: C# raw string literal #4585

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions src/basic-languages/csharp/csharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,5 +972,42 @@ testTokenization('csharp', [
{ startIndex: 45, type: 'delimiter.cs' }
]
}
],

// Raw String Literals
[
{
line: 'var singleLine = """This is a "raw string literal". It can contain characters like , \' and ".""";',
tokens: [
{ startIndex: 0, type: 'keyword.var.cs' },
{ startIndex: 3, type: '' },
{ startIndex: 4, type: 'identifier.cs' },
{ startIndex: 14, type: '' },
{ startIndex: 15, type: 'delimiter.cs' },
{ startIndex: 16, type: '' },
{ startIndex: 17, type: 'string.quote.cs' },
{ startIndex: 20, type: 'string.cs' },
{ startIndex: 93, type: 'string.quote.cs' },
{ startIndex: 96, type: 'delimiter.cs' }
]
}
],

[
{
line: 'var moreQuotes = """" As you can see,"""Raw string literals""" can start and end with more than three double-quotes when needed."""";',
tokens: [
{ startIndex: 0, type: 'keyword.var.cs' },
{ startIndex: 3, type: '' },
{ startIndex: 4, type: 'identifier.cs' },
{ startIndex: 14, type: '' },
{ startIndex: 15, type: 'delimiter.cs' },
{ startIndex: 16, type: '' },
{ startIndex: 17, type: 'string.quote.cs' },
{ startIndex: 21, type: 'string.cs' },
{ startIndex: 128, type: 'string.quote.cs' },
{ startIndex: 132, type: 'delimiter.cs' }
]
}
]
]);
17 changes: 16 additions & 1 deletion src/basic-languages/csharp/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ export const language = <languages.IMonarchLanguage>{
[/[;,.]/, 'delimiter'],

// strings
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
[/("{3,})/, { token: 'string.quote', next: '@rawstring.$1' }], // raw string literal
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-terminated string
[/"/, { token: 'string.quote', next: '@string' }],
[/\$\@"/, { token: 'string.quote', next: '@litinterpstring' }],
[/\@"/, { token: 'string.quote', next: '@litstring' }],
Expand Down Expand Up @@ -316,6 +317,20 @@ export const language = <languages.IMonarchLanguage>{
[/"/, { token: 'string.quote', next: '@pop' }]
],

rawstring: [
[/[^"]+/, 'string'],
[
/("{3,})/,
{
cases: {
'$1==$S2': { token: 'string.quote', next: '@pop' },
'@default': { token: 'string' }
}
}
],
[/["]/, 'string']
],

litstring: [
[/[^"]+/, 'string'],
[/""/, 'string.escape'],
Expand Down
Loading