Rust: Add support for highlighting raw strings and fix chars with escapes.

Rust's raw strings were previously not supported, and chars did not correctly handle escapes.

Fixes #2552
Fixes #2481
This commit is contained in:
Arlo Siemsen 2021-10-28 20:23:14 -07:00
parent 4ed52cbd2b
commit 767677f0f6
2 changed files with 71 additions and 4 deletions

View file

@ -269,6 +269,8 @@ export const language = <languages.IMonarchLanguage>{
tokenizer: {
root: [
// Raw string literals
[/r(#*)"/, { token: 'string.quote', bracket: '@open', next: '@stringraw.$1' }],
[
/[a-zA-Z][a-zA-Z0-9_]*!?|_[a-zA-Z0-9_]+/,
{
@ -287,7 +289,7 @@ export const language = <languages.IMonarchLanguage>{
// Lifetime annotations
[/'[a-zA-Z_][a-zA-Z0-9_]*(?=[^\'])/, 'identifier'],
// Byte literal
[/'\S'/, 'string.byteliteral'],
[/'(\S|@escapes)'/, 'string.byteliteral'],
// Strings
[/"/, { token: 'string.quote', bracket: '@open', next: '@string' }],
{ include: '@numbers' },
@ -326,6 +328,21 @@ export const language = <languages.IMonarchLanguage>{
[/\\./, 'string.escape.invalid'],
[/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
],
stringraw: [
[/[^"#]+/, { token: 'string' }],
[
/"(#*)/,
{
cases: {
'$1==$S2': { token: 'string.quote', bracket: '@close', next: '@pop' },
'@default': { token: 'string' }
}
}
],
[/["#]/, { token: 'string' }]
],
numbers: [
//Octal
[/(0o[0-7_]+)(@intSuffixes)?/, { token: 'number' }],