From 59974cc1c8aaff7e91cd7b14f75a9b961bd80815 Mon Sep 17 00:00:00 2001 From: Ernest Cui Date: Sun, 24 Mar 2024 20:25:30 +0800 Subject: [PATCH] feat: IR editor use custom theme --- src/modules/ir/registerIr.ts | 28 +++++++++++++++++-- .../Home/components/IrEditor/IrEditor.tsx | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/modules/ir/registerIr.ts b/src/modules/ir/registerIr.ts index 9323e13..0bf1e26 100644 --- a/src/modules/ir/registerIr.ts +++ b/src/modules/ir/registerIr.ts @@ -13,6 +13,22 @@ export function registerIr(monaco: Monaco) { id: irLanguageId }); + monaco.editor.defineTheme("ir-theme", { + base: "vs", + inherit: true, + rules: [ + { + token: "function", + foreground: "#74531f" + }, + { + token: "number.size", + foreground: "#0097ff" + } + ], + colors: {} + }); + const irKeywords = [ "FUNCTION", "DEC", @@ -32,11 +48,11 @@ export function registerIr(monaco: Monaco) { keywords: irKeywords, identifier: /[a-zA-Z_]\w*/, whitespace: /[ \t\r\n]+/, - defaultToken: "invalid", + defaultToken: "source", tokenizer: { root: [ [/#-?\d+/, "number"], - [/\d+/, "number"], + [/\d+/, "number.size"], [ /(:=)|(\+)|(-)|(\*)|(\/)|(==)|(!=)|(<=)|(<)|(>=)|(>)|(&)/, "operators" @@ -44,6 +60,14 @@ export function registerIr(monaco: Monaco) { [/:/, "delimiter"], [/;.*/, "comment"], [/@whitespace/, "white"], + [ + /(FUNCTION)(@whitespace)(@identifier)/, + ["keyword", "white", "function"] + ], + [ + /(CALL)(@whitespace)(@identifier)/, + ["keyword", "white", "function"] + ], [ /@identifier/, { diff --git a/src/pages/Home/components/IrEditor/IrEditor.tsx b/src/pages/Home/components/IrEditor/IrEditor.tsx index f16cc60..6b50d04 100644 --- a/src/pages/Home/components/IrEditor/IrEditor.tsx +++ b/src/pages/Home/components/IrEditor/IrEditor.tsx @@ -192,6 +192,7 @@ const IrEditor: React.FC = (props: IrEditorProps) => {
{ monacoRef.current = monaco; registerIr(monaco);