From 25d5e348ed6308cacb9fd913bccadf79bd422b7c Mon Sep 17 00:00:00 2001 From: WAY29 <41830147+WAY29@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:51:36 +0800 Subject: [PATCH 1/2] feat(theme): yak f-string and x-string --- .../src/main/src/utils/monacoSpec/theme.ts | 14 ++- .../main/src/utils/monacoSpec/yakEditor.ts | 98 +++++++++++++++++-- 2 files changed, 105 insertions(+), 7 deletions(-) diff --git a/app/renderer/src/main/src/utils/monacoSpec/theme.ts b/app/renderer/src/main/src/utils/monacoSpec/theme.ts index 3514e94200..fe764f4f22 100644 --- a/app/renderer/src/main/src/utils/monacoSpec/theme.ts +++ b/app/renderer/src/main/src/utils/monacoSpec/theme.ts @@ -18,7 +18,7 @@ monaco.editor.defineTheme("kurior", { "token": "libFunction", }, { - "foreground": "#ff0000", "background": "#cc7c22", + "foreground": "#ff0000", "token": "fuzz.tag.inner", fontStyle: "bold underline", }, { @@ -165,6 +165,18 @@ monaco.editor.defineTheme("kurior", { "background": "#c9d4be", "token": "string.regexp" }, + { + "foreground": "#B05A3C", + "token": "string.escape" + }, + { + "foreground": "#6A5ACD", + "token": "string.inline.expr" + }, + { + "foreground": "#FF0000", + "token": "string.invalid" + }, { "foreground": "#005273", "token": "support.function" diff --git a/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts b/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts index 7aaa222cec..4efcb2f333 100644 --- a/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts +++ b/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts @@ -184,9 +184,20 @@ export const setUpYaklangMonaco = () => { }, [] as Array), digits: /\d+(_+\d+)*/, symbols: /[=> { }, ], - - - // whitespace { include: '@whitespace' }, @@ -247,18 +255,47 @@ export const setUpYaklangMonaco = () => { // delimiter: after number because of .\d floats [/[;,.]/, 'delimiter'], + + // characters [/'[^\\']'/, 'string'], [/(')(@escapes)(')/, ['string', 'string.escape', 'string']], // strings [/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string + [/'([^'\\]|\\.)*$/, 'string.invalid'], // non-teminated string [/"/, 'string.quoted.double.js', '@string'], [/'/, 'string.quoted.single.js', '@string2'], [/`/, 'string', '@rawstring'], [/'/, 'string.invalid'], ], + fuzz_tag: [ + [/{{/, "fuzz.tag.inner", "@fuzz_tag_second"], + [/}}/, "fuzz.tag.inner", "@pop"], + [/[\w:]+}}/, "fuzz.tag.inner", "@pop"], + [/[\w:]+\(/, "fuzz.tag.inner", "@fuzz_tag_param"], + ], + fuzz_tag_second: [ + [/{{/, "fuzz.tag.second", "@fuzz_tag"], + [/}}/, "fuzz.tag.second", "@pop"], + [/[\w:]+}}/, "fuzz.tag.second", "@pop"], + [/[\w:]+\(/, "fuzz.tag.second", "@fuzz_tag_param_second"], + ], + fuzz_tag_param: [ + [/\(/, "fuzz.tag.inner", "@fuzz_tag_param"], + [/\\\)/, "bold-keyword"], + [/\)/, "fuzz.tag.inner", "@pop"], + [/{{/, "fuzz.tag.second", "@fuzz_tag_second"], + [/./, "bold-keyword"] + ], + fuzz_tag_param_second: [ + [/\\\)/, "bold-keyword"], + [/\)/, "fuzz.tag.second", "@pop"], + [/{{/, "fuzz.tag.inner", "@fuzz_tag"], + [/./, "bold-keyword"] + ], + whitespace: [ [/[ \t\r\n]+/, ''], @@ -285,20 +322,69 @@ export const setUpYaklangMonaco = () => { [/[\/*]/, 'comment.doc'] ], - string: [ + xrawstring: [ + [/{{/, "fuzz.tag.inner", "@fuzz_tag"], + [/@escapes/, 'string.escape'], + [/[^`]/, 'string'], + [/`/, 'string', '@pop'] + ], + + xstring: [ + [/{{/, "fuzz.tag.inner", "@fuzz_tag"], + [/@escapes/, 'string.escape'], [/[^\\"]+/, 'string'], + [/\\./, 'string.escape.invalid'], + [/"/, 'string', '@pop'] + ], + + xstring2: [ + [/{{/, "fuzz.tag.inner", "@fuzz_tag"], [/@escapes/, 'string.escape'], + [/[^\\']/, 'string'], + [/'/, 'string', '@pop'] + ], + + + frawstring: [ + [/@escapes/, 'string.escape'], + [/@inlineExpr/, 'string.inline.expr'], + [/@invalidInlineExpr/, 'string.invalid'], + [/[^`]/, 'string'], + [/`/, 'string', '@pop'] + ], + + fstring: [ + [/@escapes/, 'string.escape'], + [/@inlineExpr/, 'string.inline.expr'], + [/@invalidInlineExpr/, 'string.invalid'], + [/[^\\"]+/, 'string'], [/\\./, 'string.escape.invalid'], [/"/, 'string', '@pop'] ], - string2: [ + fstring2: [ + [/@escapes/, 'string.escape'], + [/@inlineExpr/, 'string.inline.expr'], + [/@invalidInlineExpr/, 'string.invalid'], [/[^\\']/, 'string'], + [/'/, 'string', '@pop'] + ], + + string: [ + [/@escapes/, 'string.escape'], + [/[^\\"]+/, 'string'], + [/\\./, 'string.invalid'], + [/"/, 'string', '@pop'] + ], + + string2: [ [/@escapes/, 'string.escape'], + [/[^\\']/, 'string'], [/'/, 'string', '@pop'] ], rawstring: [ + [/@escapes/, "string.escape"], [/[^`]/, 'string'], [/`/, 'string', '@pop'] ], From 9d3221345621661e59d960422da357dc257b8c53 Mon Sep 17 00:00:00 2001 From: WAY29 <41830147+WAY29@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:00:32 +0800 Subject: [PATCH 2/2] fix(theme): disable fuzztag render in x-string --- app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts b/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts index 4efcb2f333..a66b1ebba4 100644 --- a/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts +++ b/app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts @@ -322,15 +322,16 @@ export const setUpYaklangMonaco = () => { [/[\/*]/, 'comment.doc'] ], + // disable fuzztag because of monaco editor bug xrawstring: [ - [/{{/, "fuzz.tag.inner", "@fuzz_tag"], + // [/{{/, "fuzz.tag.inner", "@fuzz_tag"], [/@escapes/, 'string.escape'], [/[^`]/, 'string'], [/`/, 'string', '@pop'] ], xstring: [ - [/{{/, "fuzz.tag.inner", "@fuzz_tag"], + // [/{{/, "fuzz.tag.inner", "@fuzz_tag"], [/@escapes/, 'string.escape'], [/[^\\"]+/, 'string'], [/\\./, 'string.escape.invalid'], @@ -338,7 +339,7 @@ export const setUpYaklangMonaco = () => { ], xstring2: [ - [/{{/, "fuzz.tag.inner", "@fuzz_tag"], + // [/{{/, "fuzz.tag.inner", "@fuzz_tag"], [/@escapes/, 'string.escape'], [/[^\\']/, 'string'], [/'/, 'string', '@pop']