编辑器

添加xml语法高亮
This commit is contained in:
JianjunLiu 2023-03-21 15:21:34 +08:00
parent 4a7e770bf9
commit c8d44c6756
4 changed files with 87 additions and 17 deletions

View File

@ -1873,6 +1873,7 @@ type TEditer=class(TCustomcontrol) //
FSynClasses["json"]:= array(class(TJsonSynHighLighter),class(TSynCompletion),";json;"); FSynClasses["json"]:= array(class(TJsonSynHighLighter),class(TSynCompletion),";json;");
FSynClasses["js"]:= array(class(TJsSynHighLighter),class(tjssyncompletion),";js;"); FSynClasses["js"]:= array(class(TJsSynHighLighter),class(tjssyncompletion),";js;");
FSynClasses["css"]:= array(class(TcssSynHighLighter),class(tcsssyncompletion),";css;"); FSynClasses["css"]:= array(class(TcssSynHighLighter),class(tcsssyncompletion),";css;");
FSynClasses["xml"]:= array(class(TxmlSynHighLighter),class(tcsssyncompletion),";xml;");
FSynClasses["ini"]:= array(class(TINISynHigLighter),class(TSynCompletion),";ini;"); FSynClasses["ini"]:= array(class(TINISynHigLighter),class(TSynCompletion),";ini;");
FSynClasses["bat"]:= array(class(TBatSynHigLighter),class(TSynCompletion),";bat;cmd;"); FSynClasses["bat"]:= array(class(TBatSynHigLighter),class(TSynCompletion),";bat;cmd;");
FSynClasses["tfm"]:= array(class(ttfmhighlighter),class(TSynCompletion),";tfm;"); FSynClasses["tfm"]:= array(class(ttfmhighlighter),class(TSynCompletion),";tfm;");

View File

@ -1388,6 +1388,45 @@ type TJsonSynHighLighter = class(tcustomsynhighlighter)
ExecuteCommand("pairs",array(("{","}"),("[","]"))); ExecuteCommand("pairs",array(("{","}"),("[","]")));
end end
end
type TxmlSynHighLighter = class(tcustomsynhighlighter)
function create(AOwner);
begin
inherited;
ExecuteCommand("strings",array(('"'),("'")));
ExecuteCommand("keywords",array());
ExecuteCommand("rowannotes",array());
ExecuteCommand("blockannotes",array(("<!--","-->")));
ExecuteCommand("syms",array("<",">","=","?","</"));
ExecuteCommand("pairs",array(("<",">"),("</",">")));
end
function SetTToken(tokens,ttk,idx,ext);override;
begin
st := ExecuteCommand("getcurrentpairstate",">");
st1 := st.state;
d := inherited;
if not d then return ;
if st1=1 and st.state=1 then
begin
st.subitemadd();
case d.FFColor of
stringcolor,symcolor:
begin
end else
begin
if st.subitemcount()>1 then
begin
d.FFColor := 0x0000ff;
end else
d.FFColor := 0xff0000;
end
end
end
return d;
//echo "\r\n>>>",st1,"====",st2;
end
end end
type TJsSynHighLighter = class(tcustomsynhighlighter) type TJsSynHighLighter = class(tcustomsynhighlighter)
function create(AOwner); function create(AOwner);

View File

@ -3149,20 +3149,20 @@ type tcustomsynhighlighter = class(TSynHighLighter)
fregs := array(); fregs := array();
setkeyword(array("null","true","false","goto","break","for","to","while","do")); setkeyword(array("null","true","false","goto","break","for","to","while","do"));
setblockannote(array( setblockannote(array(
("/*","*/"), ("/*","*/"),
)); ));
setrowannote(array("//")); setrowannote(array("//"));
setsyms(array("+","-","*","/",";","(",")","{","}",":")); setsyms(array("+","-","*","/",";","(",")","{","}",":"));
setstring(array( setstring(array(
("'","\\"), ("'","\\"),
('"',"\\"), ('"',"\\"),
)); ));
setpairs(array( setpairs(array(
("(",")"), ("(",")"),
("[","]"), ("[","]"),
("{","}"), ("{","}"),
)); ));
setsysfun(array()); setsysfun(array());
clean(); clean();
end end
function ExecuteCommand(cmd,pm);override; function ExecuteCommand(cmd,pm);override;
@ -3205,6 +3205,14 @@ type tcustomsynhighlighter = class(TSynHighLighter)
begin begin
return setregs(pm); return setregs(pm);
end end
"getcurrentpairstate":
begin
if fcbgestate then
begin
return fcbgestate[pm];
end
return nil;
end
end ; end ;
return inherited; return inherited;
end end
@ -3243,7 +3251,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
FSatesCount := i+1; FSatesCount := i+1;
FTokens[i]:= tks; FTokens[i]:= tks;
end end
end end
function GetLineTokens(idx);override; function GetLineTokens(idx);override;
begin begin
if idx<FSatesCount then return FTokens[idx]; if idx<FSatesCount then return FTokens[idx];
@ -3377,7 +3385,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
end end
end end
d.FMATe := st.GetSate(); d.FMATe := st.GetSate();
end end
end end
function ParserTokenLines(s,b,e,cst,tokens); //½âÎö×Ö·û function ParserTokenLines(s,b,e,cst,tokens); //½âÎö×Ö·û
begin begin
@ -3439,8 +3447,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
if b>e then return cst; if b>e then return cst;
if ifarray(cst) and (cst[0]="str" or cst[0]="annote") then if ifarray(cst) and (cst[0]="str" or cst[0]="annote") then
begin begin
cst1 := cst[1];
cstL := length(cst1);
r := FindRightChar(cst[2],s,b,e,cst[3]); r := FindRightChar(cst[2],s,b,e,cst[3]);
if r=0 then //ûÕÒµ½ if r=0 then //ûÕÒµ½
begin begin
@ -3453,6 +3460,15 @@ type tcustomsynhighlighter = class(TSynHighLighter)
begin begin
Setttoken(tokens,s[b:r-1],r-1,cst); Setttoken(tokens,s[b:r-1],r-1,cst);
end end
if cst[0]="annote" then
begin
cstL := fblockstiresc[cst[1]];
end else
begin
cst1 := cst[1];
cstL := length(cst1);
end
Setttoken(tokens,s[r:(r-1+cstL)],(r-1+cstL),cst); Setttoken(tokens,s[r:(r-1+cstL)],(r-1+cstL),cst);
if r<e then if r<e then
begin begin
@ -3498,6 +3514,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
begin begin
fblockstiresa := array(); fblockstiresa := array();
fblockstiresb := array(); fblockstiresb := array();
fblockstiresc := array();
for i,v in d do for i,v in d do
begin begin
if not ifarray(d) then continue ; if not ifarray(d) then continue ;
@ -3510,7 +3527,8 @@ type tcustomsynhighlighter = class(TSynHighLighter)
fblockstiresa[v0] := st; fblockstiresa[v0] := st;
st := new TTire(); st := new TTire();
st.add(v1); st.add(v1);
fblockstiresb[v0] := st; fblockstiresb[v0] := st;
fblockstiresc[v0] := length(v1);
end end
end end
end end
@ -3680,6 +3698,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
frowstires; frowstires;
fblockstiresa; fblockstiresa;
fblockstiresb; fblockstiresb;
fblockstiresc;
fregs; fregs;
///// /////
fkeywordcolor; fkeywordcolor;

View File

@ -1827,6 +1827,15 @@ type tpairstate =class //
FIndexs := array(0); FIndexs := array(0);
FIndex := 0; FIndex := 0;
FCstate := false; FCstate := false;
FSubcount := array(0);
end
function subitemadd();
begin
FSubcount[FIndex]++;
end
function subitemcount();
begin
return FSubcount[FIndex];
end end
function GetLeft(); function GetLeft();
begin begin
@ -1837,9 +1846,9 @@ type tpairstate =class //
FIndex++; FIndex++;
FIndexs[FIndex]:=0; FIndexs[FIndex]:=0;
end else //上一个非左括号 end else //上一个非左括号
begin begin
FIndexs[FIndex]++; FIndexs[FIndex]++;
FSubcount[FIndex]:=0;
end end
FState := true; FState := true;
end end
@ -1886,6 +1895,7 @@ type tpairstate =class //
r.FCJ := FCJ; r.FCJ := FCJ;
r.FIndexs := FIndexs; r.FIndexs := FIndexs;
r.FIndex := FIndex; r.FIndex := FIndex;
r.FSubcount := FSubcount;
return r; return r;
end end
protected protected
@ -1893,6 +1903,7 @@ type tpairstate =class //
FState; FState;
FCJ; FCJ;
FIndexs; FIndexs;
FSubcount;
FIndex; FIndex;
FType; FType;