From be78680dce04f8a57f90d45043adeb33bb00d3a8 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Sun, 16 Jul 2023 13:31:17 +0200 Subject: [PATCH] ide: Different highlighting for flow breaking keywords --- uppsrc/CodeEditor/CHighlight.cpp | 6 ++-- uppsrc/CodeEditor/CInit.cpp | 47 ++++++++++++++++++++------------ uppsrc/CodeEditor/CSyntax.h | 5 ++-- uppsrc/CodeEditor/Style.cpp | 2 ++ uppsrc/CodeEditor/hl_color.i | 1 + 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/uppsrc/CodeEditor/CHighlight.cpp b/uppsrc/CodeEditor/CHighlight.cpp index 00b5efb4c..3ef8c832c 100644 --- a/uppsrc/CodeEditor/CHighlight.cpp +++ b/uppsrc/CodeEditor/CHighlight.cpp @@ -389,9 +389,9 @@ void CSyntax::Highlight(const wchar *ltext, const wchar *e, HighlightOutput& hls String iid = id; if(highlight == HIGHLIGHT_SQL) iid = ToUpper(iid); - int uq = kw_upp.Find(iid); - int nq = -1; - hls.Put(int(q - p), !include && (nq = keyword[highlight].Find(iid)) >= 0 ? hl_style[INK_KEYWORD] : + int uq = highlight == 0 ? kw_upp.Find(iid) : -1; + int nq = keyword[highlight].Find(iid); + hls.Put(int(q - p), !include && nq >= 0 ? hl_style[nq >= breakers[highlight] ? INK_BREAK_KEYWORD : INK_KEYWORD] : name[highlight].Find(iid) >= 0 ? hl_style[INK_UPP] : uq >= 0 ? uq < kw_macros ? hl_style[INK_UPPMACROS] : uq < kw_logs ? hl_style[INK_UPPLOGS] : diff --git a/uppsrc/CodeEditor/CInit.cpp b/uppsrc/CodeEditor/CInit.cpp index e4e6ffe51..c88f38523 100644 --- a/uppsrc/CodeEditor/CInit.cpp +++ b/uppsrc/CodeEditor/CInit.cpp @@ -3,6 +3,7 @@ namespace Upp { Vector > CSyntax::keyword; +Vector CSyntax::breakers; Vector > CSyntax::name; Index CSyntax::kw_upp; int CSyntax::kw_macros; @@ -24,39 +25,40 @@ void CSyntax::InitKeywords() "__finally", "__inline", "__int16", "__int32", "__int64", "__int8", "__leave", "__stdcall", "__try", "__uuidof", "alignas", "alignof", "and", "and_eq", "asm", "auto", - "bitand", "bitor", "bool", "break", "case", "catch", + "bitand", "bitor", "bool", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class", - "co_await", "co_return", "co_yield", "compl", "concept", + "co_await", "co_yield", "compl", "concept", "const", "const_cast", "consteval", "constexpr", "constinit", - "continue", "decltype", "default", "delete", "dllexport", + "decltype", "default", "delete", "dllexport", "dllimport", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "final", "float", - "for", "force_inline", "friend", "goto", "if", "import", + "for", "force_inline", "friend", "if", "import", "inline", "int", "long", "module", "mutable", "namespace", "never_inline", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "override", "private", "protected", - "public", "register", "reinterpret_cast", "requires", "return", + "public", "register", "reinterpret_cast", "requires", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", "thread", - "thread_local", "throw", "true", "try", "typedef", "typeid", + "thread_local", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", + "!break", "continue", "co_return", "goto", "return", "throw", NULL }; static const char *cs[] = { "abstract", "event", "new", "struct", "as", "explicit", "null", "switch", "base", "extern", "object", "this", - "bool", "false", "operator", "throw", - "break", "finally", "out", "true", + "bool", "false", "operator", + "finally", "out", "true", "byte", "fixed", "override", "try", "case", "float", "params", "typeof", "catch", "for", "private", "uint", "char", "foreach", "protected", "ulong", - "checked", "goto", "public", "unchecked", + "checked", "public", "unchecked", "class", "if", "readonly", "unsafe", "const", "implicit", "ref", "ushort", - "continue", "in", "return", "using", + "in", "using", "decimal", "int", "sbyte", "virtual", "default", "interface", "sealed", "volatile", "delegate", "internal", "short", "void", @@ -65,6 +67,7 @@ void CSyntax::InitKeywords() "else", "long", "static", "enum", "namespace", "string", "await", "async", "throws", "awaits", + "!break", "continue", "goto", "throw", "return", NULL }; static const char *upp[] = { @@ -103,24 +106,26 @@ void CSyntax::InitKeywords() NULL }; static const char *java[] = { - "abstract", "assert", "boolean", "break", "byte", "case", - "catch", "char", "class", "const", "continue", + "abstract", "assert", "boolean", "byte", "case", + "catch", "char", "class", "const", "default", "do", "double", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", - "synchronized", "this", "throw", "throws", "transient", + "synchronized", "this", "throws", "transient", "true", "try", "void", "volatile", "while", + "!break", "continue", "throw", NULL }; static const char *javascript[] = { - "break", "continue", "do", "for", "import", "new", "this", "void", - "case", "default", "else", "function", "in", "return", "typeof", "while", + "do", "for", "import", "new", "this", "void", + "case", "default", "else", "function", "in", "typeof", "while", "comment", "delete", "export", "if", "label", "switch", "var", "with", "catch", "enum", "throw", "class", "extends", "try", "const", "finally", "debugger", "super", "true", "false", "undefined", + "!break", "continue", "return", NULL }; static const char *css[] = { @@ -343,8 +348,16 @@ void CSyntax::InitKeywords() int CSyntax::LoadSyntax(const char *keywords[], const char *names[]) // Changed { Index& key = keyword.Add(); - while(*keywords) - key.Add(*keywords++); + int& brks = breakers.Add(); + brks = INT_MAX; + while(*keywords) { + if(**keywords == '!') { + brks = key.GetCount(); + key.Add(1 + *keywords++); + } + else + key.Add(*keywords++); + } Index & nam = name.Add(); while(*names) nam.Add(*names++); diff --git a/uppsrc/CodeEditor/CSyntax.h b/uppsrc/CodeEditor/CSyntax.h index 76b0f82c8..bf388e060 100644 --- a/uppsrc/CodeEditor/CSyntax.h +++ b/uppsrc/CodeEditor/CSyntax.h @@ -45,8 +45,9 @@ protected: static void InitKeywords(); const wchar *DoComment(HighlightOutput& hls, const wchar *p, const wchar *e); - static Vector< Index > keyword; - static Vector< Index > name; + static Vector> keyword; + static Vector breakers; + static Vector> name; static Index kw_upp; static int kw_macros, kw_logs, kw_sql_base, kw_sql_func; diff --git a/uppsrc/CodeEditor/Style.cpp b/uppsrc/CodeEditor/Style.cpp index 6ca5699a9..3fa03586a 100644 --- a/uppsrc/CodeEditor/Style.cpp +++ b/uppsrc/CodeEditor/Style.cpp @@ -157,6 +157,7 @@ void HighlightSetup::DarkTheme(bool host) SetHlStyle(INK_RAW_STRING, Color(235, 235, 255)); SetHlStyle(INK_OPERATOR, Color(214, 214, 255)); SetHlStyle(INK_KEYWORD, Color(214, 214, 255), true); + SetHlStyle(INK_BREAK_KEYWORD, Color(186, 142, 255), true, false, true); SetHlStyle(INK_UPP, Color(108, 236, 236)); SetHlStyle(PAPER_LNG, Color(13, 13, 0)); SetHlStyle(INK_ERROR, Color(255, 185, 185)); @@ -217,6 +218,7 @@ void HighlightSetup::WhiteTheme(bool host) SetHlStyle(INK_OPERATOR, LtBlue); SetHlStyle(INK_KEYWORD, LtBlue, true); + SetHlStyle(INK_BREAK_KEYWORD, Magenta, true, false, true); SetHlStyle(INK_UPP, Cyan); SetHlStyle(PAPER_LNG, Color(255, 255, 224)); SetHlStyle(INK_ERROR, LtRed); diff --git a/uppsrc/CodeEditor/hl_color.i b/uppsrc/CodeEditor/hl_color.i index 578e89f7f..7282aa08f 100644 --- a/uppsrc/CodeEditor/hl_color.i +++ b/uppsrc/CodeEditor/hl_color.i @@ -15,6 +15,7 @@ HL_COLOR(INK_CONST_STRINGOP, t_("Format field"), 1) HL_COLOR(INK_RAW_STRING, t_("Raw string literal"), 1) HL_COLOR(INK_OPERATOR, t_("Operator text"), 1) HL_COLOR(INK_KEYWORD, t_("Keyword text"), 1) +HL_COLOR(INK_BREAK_KEYWORD, t_("Flow breaking keyword text"), 1) HL_COLOR(INK_UPP, t_("U++ identifier text"), 1) HL_COLOR(PAPER_LNG, t_("t_/t__ background"), 0) HL_COLOR(INK_ERROR, t_("Umatched bracket"), 1)