Support literal interpolated strings ($@"")

This commit is contained in:
Joey Marianer 2017-01-24 15:02:42 -05:00
parent eb82671c37
commit c71ca222d3
2 changed files with 36 additions and 7 deletions

View file

@ -90,16 +90,12 @@ export var language = <ILanguage> {
// delimiters and operators // delimiters and operators
[/}/, { cases: { [/}/, { cases: {
'$S2==interpolatedstring' : { token: 'string.quote', next: '@pop' } '$S2==interpolatedstring' : { token: 'string.quote', next: '@pop' }
'$S2==litinterpstring' : { token: 'string.quote', next: '@pop' }
, '@default' : '@brackets' } }], , '@default' : '@brackets' } }],
[/[{}()\[\]]/, '@brackets'], [/[{}()\[\]]/, '@brackets'],
[/[<>](?!@symbols)/, '@brackets'], [/[<>](?!@symbols)/, '@brackets'],
[/@symbols/, { cases: { '@operators': 'delimiter', '@default' : '' } } ], [/@symbols/, { cases: { '@operators': 'delimiter', '@default' : '' } } ],
// literal string
[/\@"/, { token: 'string.quote', next: '@litstring' } ],
// interpolated string
[/\$"/, { token: 'string.quote', next: '@interpolatedstring' } ],
// numbers // numbers
[/\d*\.\d+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'], [/\d*\.\d+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'],
@ -112,6 +108,9 @@ export var language = <ILanguage> {
// strings // strings
[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string [/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
[/"/, { token: 'string.quote', next: '@string' } ], [/"/, { token: 'string.quote', next: '@string' } ],
[/\$\@"/, { token: 'string.quote', next: '@litinterpstring' } ],
[/\@"/, { token: 'string.quote', next: '@litstring' } ],
[/\$"/, { token: 'string.quote', next: '@interpolatedstring' } ],
// characters // characters
[/'[^\\']'/, 'string'], [/'[^\\']'/, 'string'],
@ -155,6 +154,15 @@ export var language = <ILanguage> {
[/"/, { token: 'string.quote', next: '@pop' } ] [/"/, { 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: [ interpolatedstring: [
[/[^\\"{]+/, 'string'], [/[^\\"{]+/, 'string'],
[/@escapes/, 'string.escape'], [/@escapes/, 'string.escape'],
@ -173,4 +181,4 @@ export var language = <ILanguage> {
[/\/\/.*$/, 'comment'], [/\/\/.*$/, 'comment'],
], ],
}, },
}; };

View file

@ -740,5 +740,26 @@ testTokenization('csharp', [
{ startIndex: 0, type: 'string.cs' }, { startIndex: 0, type: 'string.cs' },
{ startIndex: 6, type: 'string.quote.cs' }, { startIndex: 6, type: 'string.quote.cs' },
{ startIndex: 7, type: 'delimiter.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" }
]}],
]); ]);