CEDIT: optional highlighting of operators and delimiters

git-svn-id: svn://kolibrios.org@9193 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2021-09-15 21:40:33 +00:00
parent 93b5078632
commit 7524609331
6 changed files with 79 additions and 66 deletions

Binary file not shown.

View File

@ -67,11 +67,13 @@ KW3 =
KW1 = auto,default,disabled,false,none,true KW1 = auto,default,disabled,false,none,true
KW2 = KW2 =
KW3 = KW3 =
delim = =
[lang_Fasm] [lang_Fasm]
KW1 = KW1 =
KW2 = KW2 =
KW3 = KW3 =
delim = {}[]<>:,()&*/|+-\#
[lang_JSON] [lang_JSON]
KW1 = KW1 =

View File

@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Icons, Tabs, Timer; RW, Ini, EB := EditBox, Icons, Tabs, Timer;
CONST CONST
header = "CEdit (14-sep-2021)"; header = "CEdit (15-sep-2021)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON"; EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";

View File

@ -19,7 +19,7 @@
MODULE Graph; MODULE Graph;
IMPORT SYSTEM, K := KOSAPI, Lines; IMPORT SYSTEM, K := KOSAPI, Lines, Languages;
CONST CONST
@ -247,11 +247,11 @@ BEGIN
END clear; END clear;
PROCEDURE TextOut* (canvas: tCanvas; x, y: INTEGER; text: INTEGER; n: INTEGER); PROCEDURE TextOut* (canvas: tCanvas; x, y: INTEGER; text: INTEGER; n: INTEGER; delimColor: INTEGER);
CONST CONST
WCHAR_SIZE = 2; WCHAR_SIZE = 2;
VAR VAR
color, i: INTEGER; color, i, ecx: INTEGER;
c: WCHAR; c: WCHAR;
BEGIN BEGIN
IF (0 <= y) & (y <= canvas.height - canvas.font.height - 1) THEN IF (0 <= y) & (y <= canvas.height - canvas.font.height - 1) THEN
@ -271,13 +271,17 @@ BEGIN
WHILE n > 0 DO WHILE n > 0 DO
SYSTEM.GET(text + i*WCHAR_SIZE, c); SYSTEM.GET(text + i*WCHAR_SIZE, c);
IF ~Lines.isSpace(c) THEN IF ~Lines.isSpace(c) THEN
K.sysfunc6(4, x*65536 + y, LSL(28H + canvas.font.size, 24) + canvas.textColor, SYSTEM.ADR(c), 1, canvas.bitmap - 8) IF Languages.isDelim(c) THEN
ecx := LSL(28H + canvas.font.size, 24) + delimColor
ELSE
ecx := LSL(28H + canvas.font.size, 24) + canvas.textColor
END;
K.sysfunc6(4, x*65536 + y, ecx, SYSTEM.ADR(c), 1, canvas.bitmap - 8)
END; END;
INC(x, canvas.font.width); INC(x, canvas.font.width);
INC(i); INC(i);
DEC(n) DEC(n)
END END
(*K.sysfunc6(4, x*65536 + y, LSL(28H + canvas.font.size, 24) + canvas.textColor, text + i*WCHAR_SIZE, n, canvas.bitmap - 8)*)
END END
END END
END TextOut; END TextOut;
@ -285,7 +289,7 @@ END TextOut;
PROCEDURE TextOut2* (canvas: tCanvas; x, y: INTEGER; text: ARRAY OF WCHAR; n: INTEGER); PROCEDURE TextOut2* (canvas: tCanvas; x, y: INTEGER; text: ARRAY OF WCHAR; n: INTEGER);
BEGIN BEGIN
TextOut(canvas, x, y, SYSTEM.ADR(text[0]), n) TextOut(canvas, x, y, SYSTEM.ADR(text[0]), n, canvas.textColor)
END TextOut2; END TextOut2;

View File

@ -37,12 +37,17 @@ TYPE
words: ARRAY 200, 32 OF WCHAR; cnt: INTEGER words: ARRAY 200, 32 OF WCHAR; cnt: INTEGER
END; END;
tDelimiters = ARRAY 256 OF BOOLEAN;
procGetStr = PROCEDURE (secName, keyName: ARRAY OF CHAR; VAR s: ARRAY OF CHAR); procGetStr = PROCEDURE (secName, keyName: ARRAY OF CHAR; VAR s: ARRAY OF CHAR);
VAR VAR
oberonKW, cKW, pascalKW, luaKW, iniKW, fasmKW, jsonKW: ARRAY 3 OF tKeyWords; KW: ARRAY 8 OF ARRAY 3 OF tKeyWords;
Delim: ARRAY 8 OF tDelimiters;
currentLang: INTEGER;
PROCEDURE isCS* (lang: INTEGER): BOOLEAN; PROCEDURE isCS* (lang: INTEGER): BOOLEAN;
@ -63,22 +68,21 @@ END checkKW;
PROCEDURE isKey* (s: ARRAY OF WCHAR; lang, kwSet: INTEGER): BOOLEAN; PROCEDURE isKey* (s: ARRAY OF WCHAR; lang, kwSet: INTEGER): BOOLEAN;
RETURN checkKW(s, KW[lang][kwSet - 1])
END isKey;
PROCEDURE isDelim* (c: WCHAR): BOOLEAN;
VAR VAR
res: BOOLEAN; res: BOOLEAN;
BEGIN BEGIN
DEC(kwSet); IF c <= 0FFX THEN
res := FALSE; res := Delim[currentLang][ORD(c)]
CASE lang OF ELSE
|langC: res := checkKW(s, cKW[kwSet]) res := FALSE
|langOberon: res := checkKW(s, oberonKW[kwSet])
|langPascal: res := checkKW(s, pascalKW[kwSet])
|langLua: res := checkKW(s, luaKW[kwSet])
|langIni: res := checkKW(s, iniKW[kwSet])
|langFasm: res := checkKW(s, fasmKW[kwSet])
|langJSON: res := checkKW(s, jsonKW[kwSet])
END END
RETURN res RETURN res
END isKey; END isDelim;
PROCEDURE SkipString* (line: tLine; VAR pos: INTEGER; n: INTEGER); PROCEDURE SkipString* (line: tLine; VAR pos: INTEGER; n: INTEGER);
@ -360,12 +364,21 @@ BEGIN
END EnterKW; END EnterKW;
PROCEDURE loadKW (VAR KW: ARRAY OF tKeyWords; getStr: procGetStr; lang: ARRAY OF CHAR); PROCEDURE loadKW (VAR KW: ARRAY OF tKeyWords; VAR delim: tDelimiters; getStr: procGetStr; lang: ARRAY OF CHAR);
VAR VAR
s: ARRAY 16*1024 OF CHAR; s: ARRAY 16*1024 OF CHAR;
key: ARRAY 4 OF CHAR; key: ARRAY 4 OF CHAR;
i: INTEGER; i: INTEGER;
BEGIN BEGIN
FOR i := 0 TO LEN(delim) - 1 DO
delim[i] := FALSE
END;
getStr(lang, "delim", s);
i := 0;
WHILE s[i] # 0X DO
delim[ORD(s[i])] := TRUE;
INC(i)
END;
key := "KW1"; key := "KW1";
FOR i := 0 TO 2 DO FOR i := 0 TO 2 DO
KW[i].cnt := 0; KW[i].cnt := 0;
@ -376,15 +389,23 @@ BEGIN
END loadKW; END loadKW;
PROCEDURE setCurLang* (lang: INTEGER);
BEGIN
currentLang := lang
END setCurLang;
PROCEDURE init* (getStr: procGetStr); PROCEDURE init* (getStr: procGetStr);
BEGIN BEGIN
loadKW(oberonKW, getStr, "lang_Oberon"); currentLang := langText;
loadKW(cKW, getStr, "lang_C"); loadKW(KW[langText], Delim[langText], getStr, "lang_Text");
loadKW(pascalKW, getStr, "lang_Pascal"); loadKW(KW[langOberon], Delim[langOberon], getStr, "lang_Oberon");
loadKW(luaKW, getStr, "lang_Lua"); loadKW(KW[langC], Delim[langC], getStr, "lang_C");
loadKW(iniKW, getStr, "lang_Ini"); loadKW(KW[langPascal], Delim[langPascal], getStr, "lang_Pascal");
loadKW(fasmKW, getStr, "lang_Fasm"); loadKW(KW[langLua], Delim[langLua], getStr, "lang_Lua");
loadKW(jsonKW, getStr, "lang_JSON"); loadKW(KW[langIni], Delim[langIni], getStr, "lang_Ini");
loadKW(KW[langFasm], Delim[langFasm], getStr, "lang_Fasm");
loadKW(KW[langJSON], Delim[langJSON], getStr, "lang_JSON");
END init; END init;

View File

@ -127,14 +127,16 @@ BEGIN
text.lang := Lang.langJSON text.lang := Lang.langJSON
ELSE ELSE
text.lang := Lang.langText text.lang := Lang.langText
END END;
Lang.setCurLang(text.lang)
END setName; END setName;
PROCEDURE setLang* (text: tText; lang: INTEGER); PROCEDURE setLang* (text: tText; lang: INTEGER);
BEGIN BEGIN
text.lang := lang; text.lang := lang;
text.comments := TRUE text.comments := TRUE;
Lang.setCurLang(text.lang)
END setLang; END setLang;
@ -293,11 +295,11 @@ VAR
BEGIN BEGIN
SetColor(color, backColor); SetColor(color, backColor);
lexLen := MAX(MIN(line.length - lexStart, lexEnd - lexStart + 1), 0); lexLen := MAX(MIN(line.length - lexStart, lexEnd - lexStart + 1), 0);
G.TextOut(canvas, padding.left + (lexStart - text.scroll.X) * charWidth, y, Lines.getPChar(line, lexStart), lexLen) G.TextOut(canvas, padding.left + (lexStart - text.scroll.X) * charWidth, y, Lines.getPChar(line, lexStart), lexLen, color)
END PrintLex; END PrintLex;
PROCEDURE PrintComment (text: tText; line: tLine; VAR depth, i: INTEGER; y: INTEGER; backColor: INTEGER); PROCEDURE PrintComment (text: tText; line: tLine; VAR depth, i: INTEGER; w, y: INTEGER; backColor: INTEGER);
VAR VAR
lexStart: INTEGER; lexStart: INTEGER;
color: INTEGER; color: INTEGER;
@ -311,7 +313,7 @@ VAR
ELSE ELSE
color := colors.comment color := colors.comment
END; END;
lexStart := MAX(i - 2, 0); lexStart := MAX(i - w, 0);
ProcessComments(line, depth, i, 0, line.length - 1, text.lang); ProcessComments(line, depth, i, 0, line.length - 1, text.lang);
PrintLex(text, line, lexStart, i, y, color, backColor) PrintLex(text, line, lexStart, i, y, color, backColor)
END PrintComment; END PrintComment;
@ -334,20 +336,6 @@ VAR
END FL; END FL;
PROCEDURE isFASMdelim (c: WCHAR): BOOLEAN;
VAR
s: ARRAY 19 OF WCHAR;
i: INTEGER;
BEGIN
s := "{}[]<>:,()&*/|+-\#";
i := LEN(s) - 2;
WHILE (i >= 0) & (c # s[i]) DO
DEC(i)
END
RETURN i >= 0
END isFASMdelim;
PROCEDURE ident (text: tText; VAR i: INTEGER; first, y: INTEGER; line: tLine; backColor: INTEGER; cs: BOOLEAN); PROCEDURE ident (text: tText; VAR i: INTEGER; first, y: INTEGER; line: tLine; backColor: INTEGER; cs: BOOLEAN);
VAR VAR
c: WCHAR; c: WCHAR;
@ -395,7 +383,7 @@ BEGIN
n := line.length - 1; n := line.length - 1;
i := 0; i := 0;
IF (depth > 0) & (n >= 0) THEN IF (depth > 0) & (n >= 0) THEN
PrintComment(text, line, depth, i, y, backColor) PrintComment(text, line, depth, i, 2, y, backColor)
END; END;
cond := 0; cond := 0;
WHILE i <= n DO WHILE i <= n DO
@ -410,8 +398,6 @@ BEGIN
String(text, line, i, y, backColor) String(text, line, i, y, backColor)
ELSIF (U.isLetter(c) OR (c = "_")) THEN ELSIF (U.isLetter(c) OR (c = "_")) THEN
ident(text, i, i, y, line, backColor, Lang.isCS(lang)) ident(text, i, i, y, line, backColor, Lang.isCS(lang))
ELSIF isFASMdelim(c) THEN
PrintLex(text, line, i, i, y, colors.delim, backColor)
ELSIF U.isDigit(c) THEN ELSIF U.isDigit(c) THEN
hex := FALSE; hex := FALSE;
k := i; k := i;
@ -448,7 +434,7 @@ BEGIN
ELSIF (c = "*") & (cond = 1) THEN ELSIF (c = "*") & (cond = 1) THEN
depth := 1; depth := 1;
INC(i); INC(i);
PrintComment(text, line, depth, i, y, backColor); PrintComment(text, line, depth, i, 2, y, backColor);
cond := 0 cond := 0
ELSIF U.isLetter(c) OR (c = "_") OR (c = "'") OR (c = '"') THEN ELSIF U.isLetter(c) OR (c = "_") OR (c = "'") OR (c = '"') THEN
k := i; k := i;
@ -591,7 +577,7 @@ BEGIN
IF cond = 1 THEN IF cond = 1 THEN
INC(depth); INC(depth);
INC(i); INC(i);
PrintComment(text, line, depth, i, y, backColor); PrintComment(text, line, depth, i, 2, y, backColor);
cond := 0 cond := 0
ELSE ELSE
cond := 2 cond := 2
@ -615,7 +601,7 @@ BEGIN
IF Lang.LuaLong(line, i + 1) >= 0 THEN IF Lang.LuaLong(line, i + 1) >= 0 THEN
depth := Lang.LuaLong(line, i + 1)*2 + 1; depth := Lang.LuaLong(line, i + 1)*2 + 1;
INC(i); INC(i);
PrintComment(text, line, depth, i, y, backColor) PrintComment(text, line, depth, i, 2, y, backColor)
ELSE ELSE
PrintLex(text, line, i - 1, n, y, colors.comment, backColor); PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
i := n i := n
@ -630,7 +616,7 @@ BEGIN
IF k >= 0 THEN IF k >= 0 THEN
depth := (k + 1)*2; depth := (k + 1)*2;
INC(i, 2); INC(i, 2);
PrintComment(text, line, depth, i, y, backColor); PrintComment(text, line, depth, i, 2, y, backColor);
cond := 0 cond := 0
END END
ELSIF (c = "'") OR (c = '"') THEN ELSIF (c = "'") OR (c = '"') THEN
@ -698,7 +684,7 @@ BEGIN
ELSIF (c = "*") & (cond = 1) THEN ELSIF (c = "*") & (cond = 1) THEN
depth := 2; depth := 2;
INC(i); INC(i);
PrintComment(text, line, depth, i, y, backColor); PrintComment(text, line, depth, i, 2, y, backColor);
cond := 0 cond := 0
ELSIF c = "/" THEN ELSIF c = "/" THEN
IF cond = 2 THEN IF cond = 2 THEN
@ -717,8 +703,8 @@ BEGIN
ELSE ELSE
depth := 1 depth := 1
END; END;
INC(i, 2); INC(i);
PrintComment(text, line, depth, i, y, backColor); PrintComment(text, line, depth, i, 1, y, backColor);
cond := 0 cond := 0
ELSIF c = "#" THEN ELSIF c = "#" THEN
k := i; k := i;
@ -798,12 +784,10 @@ BEGIN
i := n i := n
ELSIF c = '"' THEN ELSIF c = '"' THEN
String(text, line, i, y, backColor) String(text, line, i, y, backColor)
ELSIF c = "=" THEN
PrintLex(text, line, i, i, y, colors.delim, backColor)
ELSIF c = "[" THEN ELSIF c = "[" THEN
depth := 1; depth := 1;
INC(i, 2); INC(i);
PrintComment(text, line, depth, i, y, backColor) PrintComment(text, line, depth, i, 1, y, backColor)
ELSIF U.isDigit(c) THEN ELSIF U.isDigit(c) THEN
k := i; k := i;
WHILE U.isDigit(getChar(line, i)) DO WHILE U.isDigit(getChar(line, i)) DO
@ -2014,7 +1998,7 @@ BEGIN
x := pos*charWidth + padding.left; x := pos*charWidth + padding.left;
G.SetColor(canvas, colors.selback); G.SetColor(canvas, colors.selback);
G.FillRect(canvas, x - 2, y - inter DIV 2, x + 1 + Len*charWidth, y - inter DIV 2 + charHeight); G.FillRect(canvas, x - 2, y - inter DIV 2, x + 1 + Len*charWidth, y - inter DIV 2 + charHeight);
G.TextOut(canvas, pos*charWidth + padding.left, y, Lines.getPChar(line, firstCharIdx), Len) G.TextOut(canvas, pos*charWidth + padding.left, y, Lines.getPChar(line, firstCharIdx), Len, colors.seltext)
END drawSelect; END drawSelect;
@ -2101,7 +2085,7 @@ BEGIN
END; END;
SetColor(colors.text, backColor); SetColor(colors.text, backColor);
Len := MAX(line.length - text.scroll.X, 0); Len := MAX(line.length - text.scroll.X, 0);
G.TextOut(canvas, padding.left, y, Lines.getPChar(line, text.scroll.X), MIN(Len, textsize.X + 1)); G.TextOut(canvas, padding.left, y, Lines.getPChar(line, text.scroll.X), MIN(Len, textsize.X + 1), colors.delim);
IF text.lang # Lang.langText THEN IF text.lang # Lang.langText THEN
parse(text, line, y, backColor, text.lang) parse(text, line, y, backColor, text.lang)
END; END;
@ -2242,6 +2226,8 @@ BEGIN
text.searchText := ""; text.searchText := "";
text.foundSel := 0; text.foundSel := 0;
text.CurX := -1; text.CurX := -1;
text.lang := Lang.langText;
Lang.setCurLang(Lang.langText);
setName(text, fileName); setName(text, fileName);
ASSERT(text = List.create(text)) ASSERT(text = List.create(text))
RETURN text RETURN text