设计器

升级语法解析
This commit is contained in:
JianjunLiu 2023-03-08 17:57:23 +08:00
parent c924bcd2a0
commit 5d19805db7
5 changed files with 192 additions and 29 deletions

View File

@ -1235,6 +1235,29 @@ type TPageEditerItem=class(TPageItem)
FEditer.ExecuteCommand(FEditer.ecSelGotoXY,frec[1]); FEditer.ExecuteCommand(FEditer.ecSelGotoXY,frec[1]);
FEditer.SelText := nn?(nn+";"):""; FEditer.SelText := nn?(nn+";"):"";
end end
wek := v["dstatic"];
if wek then
begin
frec := GetInfoRowCol2(wek);
if ifarray(frec[0])and ifarray(frec[1])then
begin
FEditer.ExecuteCommand(FEditer.ecGotoXY,frec[0]);
FEditer.ExecuteCommand(FEditer.ecSelGotoXY,frec[1]);
FEditer.SelText := nn?(nn+";"):"";
end
end
wek := v["weakref"];
if wek then
begin
frec := GetInfoRowCol2(wek);
if ifarray(frec[0])and ifarray(frec[1])then
begin
FEditer.ExecuteCommand(FEditer.ecGotoXY,frec[0]);
FEditer.ExecuteCommand(FEditer.ecSelGotoXY,frec[1]);
FEditer.SelText := nn?(nn+";"):"";
end
end
end end
end end
end end
@ -1972,6 +1995,13 @@ type TEditer=class(TCustomcontrol) //
FIsFinding := true; FIsFinding := true;
if not(d["c_reg"])then if not(d["c_reg"])then
begin begin
if(d["section"]="查找")and(d["btn"]="计数")then
begin
ct := "noshow";
FindAllInCurrent(d,o,nil,ct);
o.SetStatusText(format("查找到 %d处",ct));
return EndFind();
end else
if(d["section"]="查找")and(d["btn"]="全部查找")then if(d["section"]="查找")and(d["btn"]="全部查找")then
begin begin
FFindListWnd.Clean(); FFindListWnd.Clean();
@ -3598,7 +3628,7 @@ type TEditer=class(TCustomcontrol) //
L := ed.CaretY; L := ed.CaretY;
if cidx=L then continue; if cidx=L then continue;
cidx := L; cidx := L;
scap := format(" %d:(第%d行) ",idx,L)+trim(ed.LineText); scap := format(" %d:(第%d行) ",idx,L)+limitstringlength(ed.LineText);
FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":L)); FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":L));
end end
finally finally
@ -3721,13 +3751,13 @@ type TEditer=class(TCustomcontrol) //
end end
s := L.GetStringByIndex(ridx); s := L.GetStringByIndex(ridx);
ls := length(s); ls := length(s);
if data["c_case"] then s := lowercase(s);
while cx+lfs-1 <= ls do while cx+lfs-1 <= ls do
begin begin
if not FIsFinding then return-2; if not FIsFinding then return-2;
//GetAndDispatchMessageA(); //GetAndDispatchMessageA();
TryDispatch(); TryDispatch();
subs := s[cx:cx+lfs-1]; subs := s[cx:cx+lfs-1];
if data["c_case"]then subs := lowercase(subs);
if subs=fs and(wordwrap?((stringiswrapword=3)or(((stringiswrapword .& 1)or IsWordsChar(s,cx-1,ls))and((stringiswrapword .& 2)or IsWordsChar(s,cx+lfs,ls)))):true)then //找到了 if subs=fs and(wordwrap?((stringiswrapword=3)or(((stringiswrapword .& 1)or IsWordsChar(s,cx-1,ls))and((stringiswrapword .& 2)or IsWordsChar(s,cx+lfs,ls)))):true)then //找到了
begin begin
ed.ExecuteCommand(ed.ecGotoXY,array(ridx+1,cx)); ed.ExecuteCommand(ed.ecGotoXY,array(ridx+1,cx));
@ -3745,7 +3775,7 @@ type TEditer=class(TCustomcontrol) //
cx := 1; cx := 1;
end end
fo.SetStatusText("到达底部"); fo.SetStatusText("到达底部");
return-2; return -2;
end end
function FindListChoosed(o,e); function FindListChoosed(o,e);
begin begin
@ -3772,6 +3802,7 @@ type TEditer=class(TCustomcontrol) //
end end
function FindAllInCurrent(data,fo,it,rt); function FindAllInCurrent(data,fo,it,rt);
begin begin
if rt = "noshow" then fnoshow := true;
rt := 0; rt := 0;
if not it then it := GetCurrentItem(); if not it then it := GetCurrentItem();
if not it then return; if not it then return;
@ -3785,29 +3816,33 @@ type TEditer=class(TCustomcontrol) //
lfs := length(fs); lfs := length(fs);
L := ed.Lines; L := ed.Lines;
ct := L.length(); ct := L.length();
cidx := 0;
for i := 0 to ct-1 do for i := 0 to ct-1 do
begin begin
s := L.GetStringByIndex(i); s := L.GetStringByIndex(i);
ls := length(s); ls := length(s);
cx := 1; cx := 1;
if data["c_case"] then s := lowercase(s);
cidx := 0;
while cx+lfs-1 <= ls do while cx+lfs-1 <= ls do
begin begin
if not FIsFinding then return rt; if not FIsFinding then return rt;
//GetAndDispatchMessageA(); //GetAndDispatchMessageA();
TryDispatch(); TryDispatch();
subs := s[cx:cx+lfs-1]; subs := s[cx:cx+lfs-1];
if data["c_case"]then subs := lowercase(subs);
//((stringiswrapword .& 2) and (IsWordsChar(s,cx-1,ls)) ( (stringiswrapword .& 1) and IsWordsChar(s,cx+lfs,ls)) ) //((stringiswrapword .& 2) and (IsWordsChar(s,cx-1,ls)) ( (stringiswrapword .& 1) and IsWordsChar(s,cx+lfs,ls)) )
if subs=fs and(wordwrap?((stringiswrapword=3)or(((stringiswrapword .& 1)or IsWordsChar(s,cx-1,ls))and((stringiswrapword .& 2)or IsWordsChar(s,cx+lfs,ls)))):true)then //找到了 if subs=fs and(wordwrap?((stringiswrapword=3)or(((stringiswrapword .& 1)or IsWordsChar(s,cx-1,ls))and((stringiswrapword .& 2)or IsWordsChar(s,cx+lfs,ls)))):true)then //找到了
begin begin
if rt=0 then FFindListWnd.AppendItem(array("caption":format("find:%s in file:%s",fs,it.OrigScriptPath),"file":it.OrigScriptPath,"line":1)); if rt=0 and (not fnoshow) then FFindListWnd.AppendItem(array("caption":format("find:%s in file:%s",fs,it.OrigScriptPath),"file":it.OrigScriptPath,"line":1));
cx += lfs; cx += lfs;
rt++; rt++;
if cidx=i+1 then continue; if cidx then continue;
cidx := i+1; cidx := 1;
scap := format(" %d:(第%d行) ",rt,i+1)+trim(s); if not fnoshow then
FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":i+1)); begin
scap := format(" %d:(第%d行) ",rt,i+1)+limitstringlength(s);
FFindListWnd.AppendItem(array("caption":scap,"file":it.OrigScriptPath,"line":i+1));
end
continue; continue;
end end
//没找到 //没找到
@ -4603,13 +4638,21 @@ type TEditerEchoWnd=class(TSynMemoNorm) //
FProcess.OnEcho := thisfunction(TEchoToString); FProcess.OnEcho := thisfunction(TEchoToString);
FProcess.onended := thisfunction(onprocend); FProcess.onended := thisfunction(onprocend);
FProcess.onstarted := thisfunction(onprocstart); FProcess.onstarted := thisfunction(onprocstart);
AppendString("ctrl+z 停止;ctrl+c 复制选择\r\n"); AppendString("ctrl+z 停止 ; ctrl+c 复制选择\r\n");
F_Highlighter := new TSynHighLighter(self); F_Highlighter := new tcustomsynhighlighter(self);
//Highlighter := new TSynHighLighter(self); hg := F_Highlighter;
hg.ExecuteCommand("strings",array());
hg.ExecuteCommand("keywords",array("ctrl+z","ctrl+c","echo","执行结束","开始执行"));
hg.ExecuteCommand("blockannotes",array());
hg.ExecuteCommand("rowannotes",array());
//hg.ExecuteCommand("regs",array("^(V|v)\\d":0x00ff00));
hg.ExecuteCommand("syms",array(":",";"));
hg.ExecuteCommand("pairs",array(("开始执行","执行结束")));
self.HighLighter := hg;
end end
function onprocstart(o,e); function onprocstart(o,e);
begin begin
AppendString("开始执行"); AppendString("开始执行 ");
end end
function onprocend(o,e); function onprocend(o,e);
begin begin
@ -5010,19 +5053,24 @@ type TFindWnd=class(TPage)
FBtn_Find := new TFindBtn(self); FBtn_Find := new TFindBtn(self);
FBtn_replace := new TFindBtn(self); FBtn_replace := new TFindBtn(self);
FBtn_Count := new TFindBtn(self); // 计数 FBtn_Count := new TFindBtn(self); // 计数
FBtn_Count_a := new TFindBtn(self); // 计数
FBtn_replaceall := new TFindBtn(self); FBtn_replaceall := new TFindBtn(self);
FBtn_Find.caption := "查找"; FBtn_Find.caption := "查找";
FBtn_replace.caption := "替换"; FBtn_replace.caption := "替换";
FBtn_Count_a.Caption := "计数";
FBtn_Count.caption := "全部查找"; FBtn_Count.caption := "全部查找";
FBtn_replaceall.caption := "全部替换"; FBtn_replaceall.caption := "全部替换";
FBtn_Find.top := lg; FBtn_Find.top := lg;
FBtn_Find.parent := self; FBtn_Find.parent := self;
FBtn_replace.top := lg+lg; FBtn_replace.top := lg+lg;
FBtn_Count_a.top := lg+lg;
FBtn_replace.parent := self; FBtn_replace.parent := self;
FBtn_Count_a.parent := self;
FBtn_replaceall.top := lg+lg+lg; FBtn_replaceall.top := lg+lg+lg;
FBtn_replaceall.parent := self; FBtn_replaceall.parent := self;
FBtn_Find.OnClick := thisfunction(FindBtnClick); FBtn_Find.OnClick := thisfunction(FindBtnClick);
FBtn_replace.OnClick := thisfunction(FindBtnClick); FBtn_replace.OnClick := thisfunction(FindBtnClick);
FBtn_Count_a.OnClick := thisfunction(FindBtnClick);
FBtn_Count.OnClick := thisfunction(FindBtnClick); FBtn_Count.OnClick := thisfunction(FindBtnClick);
FBtn_replaceall.OnClick := thisfunction(FindBtnClick); FBtn_replaceall.OnClick := thisfunction(FindBtnClick);
FBtn_Count.top := lg+lg+lg+lg; FBtn_Count.top := lg+lg+lg+lg;
@ -5172,6 +5220,7 @@ type TFindWnd=class(TPage)
FEdit_dir_btn.visible := false; FEdit_dir_btn.visible := false;
FEdit_type.visible := false; FEdit_type.visible := false;
FEdit_repace.visible := false; FEdit_repace.visible := false;
FBtn_Count_a.visible := true;
FBtn_replace.visible := false; FBtn_replace.visible := false;
FBtn_count.Visible := true; FBtn_count.Visible := true;
FBtn_Replaceall.Visible := false; FBtn_Replaceall.Visible := false;
@ -5183,6 +5232,7 @@ type TFindWnd=class(TPage)
begin begin
flabels[1].Visible := true; flabels[1].Visible := true;
for i := 2 to 3 do flabels[i].Visible := false; for i := 2 to 3 do flabels[i].Visible := false;
FBtn_Count_a.visible := false;
FEdit_dir.visible := false; FEdit_dir.visible := false;
FEdit_dir_btn.visible := false; FEdit_dir_btn.visible := false;
FEdit_type.visible := false; FEdit_type.visible := false;
@ -5197,6 +5247,7 @@ type TFindWnd=class(TPage)
"文件查找": "文件查找":
begin begin
for i := 1 to 3 do flabels[i].Visible := true; for i := 1 to 3 do flabels[i].Visible := true;
FBtn_Count_a.visible := false;
FEdit_dir.visible := true; FEdit_dir.visible := true;
FEdit_dir_btn.Visible := true; FEdit_dir_btn.Visible := true;
FEdit_type.visible := true; FEdit_type.visible := true;
@ -5257,6 +5308,7 @@ type TFindWnd=class(TPage)
end end
end end
private private
weakref
FStatus; FStatus;
FDirChooser; FDirChooser;
//查找 //查找
@ -5267,6 +5319,7 @@ type TFindWnd=class(TPage)
FEdit_dir_btn; FEdit_dir_btn;
FBtn_Find; FBtn_Find;
FBtn_replace; FBtn_replace;
FBtn_Count_a;
FBtn_Replaceall; FBtn_Replaceall;
FBtn_Count; // 计数 FBtn_Count; // 计数
flabels; flabels;
@ -5277,6 +5330,7 @@ type TFindWnd=class(TPage)
FCheck_reg; FCheck_reg;
FCheck_subdir; FCheck_subdir;
FCheck_gt; FCheck_gt;
autoref
end end
type TGoToLineWnd=class(TVCForm) //跳转 type TGoToLineWnd=class(TVCForm) //跳转
@ -5469,6 +5523,22 @@ function gettslexe();
begin begin
return static gettslexefullpath(); return static gettslexefullpath();
end end
function limitstringlength(s);
begin
len := length(s);
n := 150;
if len>n then
begin
if bytetype(s,n)=1 then
begin
return trim(s[1:(n-1)])+"...";
end else
begin
return trim(s[1:n])+"...";
end
end
return trim(s);
end
{$ifdef linux} {$ifdef linux}
function HtmlHelpA() function HtmlHelpA()
begin begin

View File

@ -1379,7 +1379,7 @@ type TJsonSynHighLighter = class(tcustomsynhighlighter)
function create(AOwner); function create(AOwner);
begin begin
inherited; inherited;
ExecuteCommand("string",array(('"',"\\"),("'","\\"))); ExecuteCommand("strings",array(('"',"\\"),("'","\\")));
ExecuteCommand("keywords",array("null","true","false")); ExecuteCommand("keywords",array("null","true","false"));
ExecuteCommand("rowannotes",array()); ExecuteCommand("rowannotes",array());
ExecuteCommand("blockannotes",array()); ExecuteCommand("blockannotes",array());
@ -1395,7 +1395,7 @@ type TJsSynHighLighter = class(tcustomsynhighlighter)
keywordcolor := 0xff0000; keywordcolor := 0xff0000;
stringcolor := 0x968080; stringcolor := 0x968080;
annotationcolor := 0x8D9600; annotationcolor := 0x8D9600;
ExecuteCommand("string",array(('"',"\\"))); ExecuteCommand("strings",array(('"',"\\")));
ExecuteCommand("keywords",jskeywords1()); ExecuteCommand("keywords",jskeywords1());
ExecuteCommand("rowannotes",array("//")); ExecuteCommand("rowannotes",array("//"));
ExecuteCommand("blockannotes",array(("/*","*/"))); ExecuteCommand("blockannotes",array(("/*","*/")));
@ -1421,7 +1421,7 @@ type TcssSynHighLighter = class(tcustomsynhighlighter)
keywordcolor := 0xff0000; keywordcolor := 0xff0000;
stringcolor := 0x968080; stringcolor := 0x968080;
annotationcolor := 0x8D9600; annotationcolor := 0x8D9600;
ExecuteCommand("string",array(('"',"\\"))); ExecuteCommand("strings",array(('"',"\\")));
ExecuteCommand("keywords",getcsswords()); ExecuteCommand("keywords",getcsswords());
ExecuteCommand("rowannotes",array()); ExecuteCommand("rowannotes",array());
ExecuteCommand("blockannotes",array(("/*","*/"))); ExecuteCommand("blockannotes",array(("/*","*/")));
@ -1436,7 +1436,7 @@ type ttfmhighlighter = class(tcustomsynhighlighter)
function create(AOwner); function create(AOwner);
begin begin
inherited; inherited;
ExecuteCommand("string",array(('"',"\\"))); ExecuteCommand("strings",array(('"',"\\")));
ExecuteCommand("keywords",array("object","end","inherited")); ExecuteCommand("keywords",array("object","end","inherited"));
ExecuteCommand("rowannotes",array()); ExecuteCommand("rowannotes",array());
ExecuteCommand("blockannotes",array(("{","}"))); ExecuteCommand("blockannotes",array(("{","}")));

View File

@ -217,6 +217,26 @@ type tslparser = class(tslparserbase) //
priv := tk; priv := tk;
continue; continue;
end end
if tk in array("weakref","autoref") then
begin
continue;
end
if tk="[" and tp=TT_SYM then
begin
wkps := pos;
while true do
begin
ctoken(tk,tp,pos,row);
if ifnil(tk) then break;
if tk="]" and tp=TT_SYM then
begin
weakflag := array("beg":wkps,"end":pos);
break;
end
end
if ifnil(tk) then break;
if tk="]" then continue;
end
if tk="uses" and tp=TT_IDE then if tk="uses" and tp=TT_IDE then
begin begin
usb := pos; usb := pos;
@ -235,13 +255,28 @@ type tslparser = class(tslparserbase) //
if tk="static" and tp=TT_IDE then if tk="static" and tp=TT_IDE then
begin begin
if not r["filed"]then r["filed"]:= array(); if not r["filed"]then r["filed"]:= array();
staticflag := array("beg":pos);
sf := parserfiled(); sf := parserfiled();
for i := 0 to length(sf)-1 do for i := 0 to length(sf)-1 do
begin begin
if i=0 then
begin
staticflag["end"] := sf[i]["beg"]-1;
end
sf[i]["static"]:= true; sf[i]["static"]:= true;
sf[i]["staticpos"]:= pos; sf[i]["staticpos"]:= pos;
sf[i]["priv"]:= priv; sf[i]["priv"]:= priv;
end end
if (length(sf)=1) then
begin
sf[0]["dstatic"] := staticflag;
end
if weakflag and (length(sf)=1) then
begin
sf[0]["weakref"] := weakflag;
weakflag := nil;
end
filed union=sf; filed union=sf;
end else end else
if tk="function" or tk="procedure" then if tk="function" or tk="procedure" then
@ -281,7 +316,13 @@ type tslparser = class(tslparserbase) //
else else
begin begin
bpos(); bpos();
filed union=parserfiled(priv); sf:=parserfiled(priv);
if weakflag and (length(sf)=1) then
begin
sf[0]["weakref"] := weakflag;
weakflag := nil;
end
filed union= sf;
end end
end end
end end
@ -326,9 +367,18 @@ type tslparser = class(tslparserbase) //
if rcount then if rcount then
begin begin
r[rcount]["last"]:= true; r[rcount]["last"]:= true;
end r[rcount]["beg"] := r[rcount]["precomma"];
r[rcount]["end"]:= pos; if not (r[rcount]["end"]>0) then
return r; begin
r[rcount]["end"] := pos-1;
end
end else
begin
r[rcount]["end"]:= pos;
end
break;
// return r;
end else end else
if tk="," then if tk="," then
begin begin
@ -336,12 +386,20 @@ type tslparser = class(tslparserbase) //
begin begin
r[rcount]["nextcomma"]:= pos; r[rcount]["nextcomma"]:= pos;
end else end else
r[rcount]["first"]:= true; begin
r[rcount]["first"]:= true;
end
r[rcount]["end"] := pos;
rcount++; rcount++;
r[rcount]["precomma"]:= pos; r[rcount]["precomma"]:= pos;
end else end else
if tk=":" then if tk=":" then
begin begin
if rcount>0 then
begin
r[rcount]["end"] := pos-1;
end
tpv := parsertype(); tpv := parsertype();
for i := 0 to length(r)-1 do for i := 0 to length(r)-1 do
begin begin
@ -360,7 +418,8 @@ type tslparser = class(tslparserbase) //
begin begin
r[i]["type"]:= "array"; r[i]["type"]:= "array";
end end
return r; break;
// return r;
end else end else
if tk="of" then if tk="of" then
begin begin
@ -376,6 +435,7 @@ type tslparser = class(tslparserbase) //
r[rcount]["priv"]:= priv; r[rcount]["priv"]:= priv;
end end
end end
len := length(r);
return r; return r;
end end
function parserproperty(); function parserproperty();
@ -516,7 +576,7 @@ type tslparserbase= class //
begin begin
TT_IDE := "±êʾ·û"; TT_IDE := "±êʾ·û";
TT_STR := "×Ö·û´®"; TT_STR := "×Ö·û´®";
TT_SYM := "分割符"; TT_SYM := "·Ö¸î";
TT_OK := true; TT_OK := true;
end end
end end

View File

@ -522,9 +522,10 @@ type tcontrol = class(tcomponent)
begin begin
if idx=-1 then if idx=-1 then
begin begin
FControls.append(actrl); wkactl := makeweakref(actrl);
FControls.append(wkactl);
actrl.FParent := self(true); actrl.FParent := self(true);
ControlAppended(actrl); ControlAppended(wkactl);
ifop := true; ifop := true;
end end
end end

View File

@ -770,6 +770,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
rc[0]:= Max(rc[0],FGutter.Width); rc[0]:= Max(rc[0],FGutter.Width);
//echo tostn(array(FirstLine, LastLine, FirstCol, LastCol)); //echo tostn(array(FirstLine, LastLine, FirstCol, LastCol));
cvs := Canvas; cvs := Canvas;
cvs.Font := font;
bcvs := new TCanvsRgnClipAutoSave(cvs,rc); bcvs := new TCanvsRgnClipAutoSave(cvs,rc);
PaintTextLines(RC,FirstLine,LastLine,FirstCol,LastCol); PaintTextLines(RC,FirstLine,LastLine,FirstCol,LastCol);
end end
@ -3144,7 +3145,8 @@ type tcustomsynhighlighter = class(TSynHighLighter)
fannotationcolor := 0xaa3300; fannotationcolor := 0xaa3300;
fignorecase := false;//忽略大小写 fignorecase := false;//忽略大小写
FChangeDeal := true; FChangeDeal := true;
FTokens := array(); FTokens := 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(
("/*","*/"), ("/*","*/"),
@ -3199,6 +3201,10 @@ type tcustomsynhighlighter = class(TSynHighLighter)
begin begin
return setpairs(pm); return setpairs(pm);
end end
"regs":
begin
return setregs(pm);
end
end ; end ;
return inherited; return inherited;
end end
@ -3256,6 +3262,9 @@ type tcustomsynhighlighter = class(TSynHighLighter)
if ifsysfun(bttk) then if ifsysfun(bttk) then
begin begin
d.FFColor := fsysfuncolor ; d.FFColor := fsysfuncolor ;
end else
begin
dereg(d,bttk);
end end
dopair(d,bttk); dopair(d,bttk);
end else end else
@ -3324,6 +3333,17 @@ type tcustomsynhighlighter = class(TSynHighLighter)
end end
end end
end end
function dereg(d,ttk);
begin
for i,v in fregs do
begin
if parseregexpr(i,ttk,"",r,mp,ml)=1 then
begin
d.FFColor := v;
return ;
end
end
end
function dopair(d,bttk); //处理配对信息 function dopair(d,bttk); //处理配对信息
begin begin
if FIgnoreCase then if FIgnoreCase then
@ -3531,6 +3551,17 @@ type tcustomsynhighlighter = class(TSynHighLighter)
end end
end end
end end
function setregs(d);
begin
fregs := array();
for rg,v in d do
begin
if ifnil(v) then continue;
if not(rg and ifstring(rg)) then continue;
fregs[rg] := v
end
end
function setpairs(d);//设置配对 function setpairs(d);//设置配对
begin begin
fswordpairs := array(); fswordpairs := array();
@ -3648,7 +3679,8 @@ type tcustomsynhighlighter = class(TSynHighLighter)
fsysfuntires; fsysfuntires;
frowstires; frowstires;
fblockstiresa; fblockstiresa;
fblockstiresb; fblockstiresb;
fregs;
///// /////
fkeywordcolor; fkeywordcolor;
fsysfuncolor; fsysfuncolor;