ide: Different highlighting for flow breaking keywords

This commit is contained in:
Mirek Fidler 2023-07-16 13:31:17 +02:00
parent 09864e391c
commit be78680dce
5 changed files with 39 additions and 22 deletions

View file

@ -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] :

View file

@ -3,6 +3,7 @@
namespace Upp {
Vector <Index<String> > CSyntax::keyword;
Vector<int> CSyntax::breakers;
Vector <Index<String> > CSyntax::name;
Index<String> 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<String>& 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 <String>& nam = name.Add();
while(*names)
nam.Add(*names++);

View file

@ -45,8 +45,9 @@ protected:
static void InitKeywords();
const wchar *DoComment(HighlightOutput& hls, const wchar *p, const wchar *e);
static Vector< Index<String> > keyword;
static Vector< Index<String> > name;
static Vector<Index<String>> keyword;
static Vector<int> breakers;
static Vector<Index<String>> name;
static Index<String> kw_upp;
static int kw_macros, kw_logs, kw_sql_base, kw_sql_func;

View file

@ -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);

View file

@ -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)