editor/pybricksMicroPython: improve f-string highlighting

Fixes: https://github.com/pybricks/support/issues/875
This commit is contained in:
David Lechner
2022-12-27 17:35:11 -06:00
committed by David Lechner
parent 5bef7e2637
commit 43a6f63eaf
2 changed files with 40 additions and 3 deletions
+39 -2
View File
@@ -229,9 +229,43 @@ export const language = <monaco.languages.IMonarchLanguage>{
// Recognize strings, including those broken across lines with \ (but not without)
strings: [
[/'$/, 'string.escape', '@popall'],
[/'/, 'string.escape', '@stringBody'],
[/([fF]|[fF][rR]|[rR][fF])?'/, 'string.escape', '@fStringBody'],
[/[rRuUbB]?'/, 'string.escape', '@stringBody'],
[/"$/, 'string.escape', '@popall'],
[/"/, 'string.escape', '@dblStringBody'],
[/([fF]|[fF][rR]|[rR][fF])?"/, 'string.escape', '@dblFStringBody'],
[/[rRuUbB]?"/, 'string.escape', '@dblStringBody'],
],
fStringBody: [
[/([^\\'{}]|\{\{|\}\}(?!\}[^}]))+$/, 'string', '@popall'],
[/([^\\'{}]|\{\{|\}\}(?!\}[^}]))+/, 'string'],
[/\\./, 'string'],
[/'/, 'string.escape', '@popall'],
[/\\$/, 'string'],
[
/\{/,
{
token: 'delimiter.curly',
next: '@fStringReplacement',
nextEmbedded: pybricksMicroPythonId,
},
],
[/\}/, 'delimiter.curly'],
],
dblFStringBody: [
[/([^\\"{}]|\{\{|\}\}(?!\}[^}]))+$/, 'string', '@popall'],
[/([^\\"{}]|\{\{|\}\}(?!\}[^}]))+/, 'string'],
[/\\./, 'string'],
[/"/, 'string.escape', '@popall'],
[/\\$/, 'string'],
[
/\{/,
{
token: 'delimiter.curly',
next: '@fStringReplacement',
nextEmbedded: pybricksMicroPythonId,
},
],
[/\}/, 'delimiter.curly'],
],
stringBody: [
[/[^\\']+$/, 'string', '@popall'],
@@ -247,6 +281,9 @@ export const language = <monaco.languages.IMonarchLanguage>{
[/"/, 'string.escape', '@popall'],
[/\\$/, 'string'],
],
fStringReplacement: [
[/\}/, { token: '@rematch', next: '@pop', nextEmbedded: '@pop' }],
],
operators: [
[