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

fix rust raw string highlighting #2552 #146

Merged
merged 5 commits into from
Jul 15, 2021
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
38 changes: 38 additions & 0 deletions src/rust/rust.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@ testTokenization('rust', [
]
}
],
// Raw String
[
{
line: 'r"This is a raw string" ',
tokens: [
{ startIndex: 0, type: 'string.raw.rust' },
{ startIndex: 23, type: 'white.rust' },
]
}
],
[
{
line: 'r#"This is a raw string"# ',
tokens: [
{ startIndex: 0, type: 'string.raw.rust' },
{ startIndex: 25, type: 'white.rust' },
]
}
],
[
{
line: 'r##"This is a# raw string"## ',
tokens: [
{ startIndex: 0, type: 'string.raw.rust' },
{ startIndex: 28, type: 'white.rust' },
]
}
],
[
{
line: 'r###"This is ##"#"##a raw### string"### ',
tokens: [
{ startIndex: 0, type: 'string.raw.rust' },
{ startIndex: 39, type: 'white.rust' },
]
}
],

// Byte literal
[
{
Expand Down
6 changes: 6 additions & 0 deletions src/rust/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export const language = <languages.IMonarchLanguage>{

tokenizer: {
root: [
// Raw string literals
[/r(?=#*")/, { token: 'string.raw', bracket: '@open', next: '@stringraw' }],
[
/[a-zA-Z][a-zA-Z0-9_]*!?|_[a-zA-Z0-9_]+/,
{
Expand Down Expand Up @@ -327,6 +329,10 @@ export const language = <languages.IMonarchLanguage>{
[/\\./, 'string.escape.invalid'],
[/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
],
stringraw: [
[/[^#"]/, 'string.raw'],
[/(#*)".*?"\1/, { token: 'string.raw', bracket: '@close', next: '@pop' }]
],
numbers: [
//Octal
[/(0o[0-7_]+)(@intSuffixes)?/, { token: 'number' }],
Expand Down