Skip to content

Commit

Permalink
Merge pull request #1401 from yaklang/feat/theme/yak
Browse files Browse the repository at this point in the history
feat(theme): yak f-string and x-string
  • Loading branch information
b1rdfree authored Feb 5, 2024
2 parents 7ac18fe + 9d32213 commit 03ec2fa
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 7 deletions.
14 changes: 13 additions & 1 deletion app/renderer/src/main/src/utils/monacoSpec/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ monaco.editor.defineTheme("kurior", {
"token": "libFunction",
},
{
"foreground": "#ff0000", "background": "#cc7c22",
"foreground": "#ff0000",
"token": "fuzz.tag.inner", fontStyle: "bold underline",
},
{
Expand Down Expand Up @@ -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"
Expand Down
99 changes: 93 additions & 6 deletions app/renderer/src/main/src/utils/monacoSpec/yakEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,20 @@ export const setUpYaklangMonaco = () => {
}, [] as Array<string>),
digits: /\d+(_+\d+)*/,
symbols: /[=><!~?:&|+\-*\/\^%]+/,
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4})/,
inlineExpr: /\$\{[^}]*\}/,
invalidInlineExpr: /\$\{[^}]*$/,
tokenizer: {
root: [

// f-strings
[/f"/, 'string.quoted.double.js', '@fstring'],
[/f'/, 'string.quoted.single.js', '@fstring2'],
[/f`/, 'string', '@frawstring'],
// x-strings
[/x"/, 'string.quoted.double.js', '@xstring'],
[/x'/, 'string.quoted.single.js', '@xstring2'],
[/x`/, 'string', '@xrawstring'],
// identifiers and keywords
[/_(?!\w)/, 'keyword.$0'],
[
Expand All @@ -210,9 +221,6 @@ export const setUpYaklangMonaco = () => {
},
],




// whitespace
{ include: '@whitespace' },

Expand Down Expand Up @@ -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]+/, ''],
Expand All @@ -285,20 +322,70 @@ export const setUpYaklangMonaco = () => {
[/[\/*]/, 'comment.doc']
],

string: [
// disable fuzztag because of monaco editor bug
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']
],
Expand Down

0 comments on commit 03ec2fa

Please sign in to comment.