diff --git a/designer/utslsynmemo.tsf b/designer/utslsynmemo.tsf index b6e3cfb..430e50b 100644 --- a/designer/utslsynmemo.tsf +++ b/designer/utslsynmemo.tsf @@ -1231,606 +1231,40 @@ type TINISynHigLighter = class(TSynHighLighter) return r; end end -type TJsonSynHighLighter = class(TSynHighLighter) - function Create(AOwner); +type TJsonSynHighLighter = class(tcustomsynhighlighter) + function create(AOwner); begin inherited; - Clean(); - FChangeDeal := true; - end - function Clean();override; - begin - // { " - FTokens := array(); - FSates := array(0); //状态 - FBBStates := array(new TBBState(")")); - FBEStates := array(new TBBState("}")); - FMBStates := array(new TBBState("]")); - FSatesCount := 1; //改变的行 - - end - function Recycling();override; - begin - - inherited; - Clean(); - end - function SetInValidateIndex(idx); override; //当前改变的行 - begin - idx := max(1,idx); - if not(FChangeDeal) and idx>FSatesCount then return ; - fdolastline := idx-2; - if length(FSates)>=idx then - FSatesCount := idx; - else FSatesCount := length(FSates)-1; - if FSatesCount = 1 then Clean(); - FChangeDeal := false; - end - function ParserTokenLines(s,b,e,cst,tokens); - begin -label L_XCDG; - if cst=0 then - begin - idx := b; - ttk := ""; - while idx<=e do - begin - vi := s[idx]; - case vi of - " ","\t": - begin - SetTToken(tokens,ttk,idx-1); - end - "(",")": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,")"); - end - "{","}": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,"}"); - end - "[","]": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,"]"); - end - ":",",": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,vi); - end - '"': - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,'"'); - return ParserTokenLines(s,idx+1,e,'"',tokens); - end else - begin - ttk+=vi; - end - - end ; - idx++; - end - SetTToken(tokens,ttk,idx-1); - end else //查找 - begin - if b>e then return cst; - r := FindRightChar(cst,s,b,e,"\\"); - if r=0 then //没找到 - begin - Setttoken(tokens,s[b:],e,cst); - return cst; - end else //找到 - if r<=e then - begin - if b=LastLine then return ; - fdolastline := LastLine; - for i:= FSatesCount-1 to LastLine do - begin - if i<0 then continue; - s := ls.GetStringByIndex(i); - cst := FSates[i]; - tks := array(); - FCBBState := FBBStates[i].Clone; - FCBEState := FBEStates[i].Clone; - FCMBState := FMBStates[i].Clone; - FSates[i+1] := ParserTokenLines(s,1,length(s),cst,tks); - FBBStates[i+1] :=FCBBState;//.Clone; - FBEStates[i+1] := FCBEState;//.Clone; - FMBStates[i+1] := FCMBState; - FSatesCount := i+1; - FTokens[i] := tks; - end - end - function GetLineTokens(idx);override; - begin - if idxe then return 0; - continue; - end - if s[i]=c then //找到了 - begin - return i; - end - i++; - end - return 0; //没找到 - for i := b to e do - begin - if s[i]=c then //找到了 - begin - return i; - end - end - + ExecuteCommand("string",array(('"',"\\"))); + ExecuteCommand("keywords",array("null","true","false")); + ExecuteCommand("rowannotes",array()); + ExecuteCommand("blockannotes",array()); + ExecuteCommand("syms",array("{","}","[","]","<",">",":",",","=")); + ExecuteCommand("pairs",array(("{","}"),("[","]"))); end - private - fdolastline; - FTokens; - FSates; - FSatesCount; - - FCBBState; - FCBEState; - FCMBState; - FBBStates; - FBEStates; - FMBStates ; end -type ttfmhighlighter = class(TSynHighLighter) - function Create(AOwner); + +type ttfmhighlighter = class(tcustomsynhighlighter) + function create(AOwner); begin inherited; - Clean(); - FChangeDeal := true; - end - function Clean();override; - begin - // { " - FTokens := array(); - FSates := array(0); //状态 - FBBStates := array(new TBBState(")")); - FBEStates := array(new TBBState("}")); - FMBStates := array(new TBBState("]")); - FbgedStates := array(new TBBState("end")); - FjkhStates := array(new TBBState(">")); - FSatesCount := 1; //改变的行 - end - function Recycling();override; - begin - - inherited; - Clean(); - end - function SetInValidateIndex(idx); override; //当前改变的行 - begin - idx := max(1,idx); - if not(FChangeDeal) and idx>FSatesCount then return ; - fdolastline := idx-2; - if length(FSates)>=idx then - FSatesCount := idx; - else FSatesCount := length(FSates)-1; - if FSatesCount = 1 then Clean(); - FChangeDeal := false; - end - function ParserTokenLines(s,b,e,cst,tokens); - begin -label L_XCDG; - if cst=0 then - begin - idx := b; - ttk := ""; - while idx<=e do - begin - vi := s[idx]; - case vi of - " ","\t": - begin - SetTToken(tokens,ttk,idx-1); - end - "(",")": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,")"); - end - "{","}": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,"}"); - end - "[","]": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,"]"); - end - "<",">": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,">"); - end - ":",",": - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,vi); - end - '"': - begin - SetTToken(tokens,ttk,idx-1); - SetTToken(tokens,vi,idx,'"'); - return ParserTokenLines(s,idx+1,e,'"',tokens); - end else - begin - ttk+=vi; - end - - end ; - idx++; - end - SetTToken(tokens,ttk,idx-1); - end else //查找 - begin - if b>e then return cst; - r := FindRightChar(cst,s,b,e,"\\"); - if r=0 then //没找到 - begin - Setttoken(tokens,s[b:],e,cst); - return cst; - end else //找到 - if r<=e then - begin - if b=LastLine then return ; - fdolastline := LastLine; - for i:= FSatesCount-1 to LastLine do - begin - if i<0 then continue; - s := ls.GetStringByIndex(i); - cst := FSates[i]; - tks := array(); - FCBBState := FBBStates[i].Clone; - FCBEState := FBEStates[i].Clone; - FCMBState := FMBStates[i].Clone; - fcbgesate := FbgedStates[i].Clone; - fcjkhState := FjkhStates[i].Clone; - FSates[i+1] := ParserTokenLines(s,1,length(s),cst,tks); - FBBStates[i+1] :=FCBBState;//.Clone; - FBEStates[i+1] := FCBEState;//.Clone; - FMBStates[i+1] := FCMBState; - FbgedStates[i+1] := fcbgesate; - FjkhStates[i+1] := fcjkhState; - FSatesCount := i+1; - FTokens[i] := tks; - end - end - function GetLineTokens(idx);override; - begin - if idx") then d.FFColor := 0xFF0000; - if ext=">" and tk="<" then - begin - fcjkhState.GetLeft(); - d.FMATe := fcjkhState.GetSate(); - end else - if ext=">" and tk=">" then - begin - fcjkhState.GetRight(); - d.FMATe := fcjkhState.GetSate(); - end else - if ext="}" and tk="{" then - begin - FCBEState.GetLeft(); - d.FMATe := FCBEState.GetSate(); - end else - if ext="}" and tk="}" then - begin - FCBEState.GetRight(); - d.FMATe := FCBEState.GetSate(); - end else - if ext="]" and tk="[" then - begin - FCMBState.GetLeft(); - d.FMATe := FCMBState.GetSate(); - - end else - if ext="]" and tk="]" then - begin - FCMBState.GetRight(); - d.FMATe := FCMBState.GetSate(); - end else - if ext=")" and tk="(" then - begin - FCBBState.GetLeft(); - d.FMATe := FCBBState.GetSate(); - - end else - if ext=")" and tk=")" then - begin - FCBBState.GetRight(); - d.FMATe := FCBBState.GetSate(); - end else - if ext='"' then - begin - D.FFColor := 0x8B008B; - end else - if tk in array("true","false","null") then - begin - d.FFColor := 0x0000FF; - end else - if tk ="object" then - begin - d.FFColor := 0x0000FF; - fcbgesate.GetLeft(); - d.FMATe := fcbgesate.GetSate(); - end else - if tk="end" then - begin - d.FFColor := 0x0000FF; - fcbgesate.GetRight(); - d.FMATe := fcbgesate.GetSate(); - end else - if tk in array(":",",") then - begin - d.FFColor := 0x0000FF; - end else - if StrIsANumber(tk) then d.FFColor := 0x666666; - return d; - - end - private - function StrIsANumber(s); - begin - if not s then return 0; - r := (1=ParseRegExpr("^[+-]?[\\d]+",s,"",result,MPos,Mlen)) ; - return r; - end - function FindRightChar(c,s,b,e,zy); //查找封闭的字符 - begin - i := b; - while i<=e do - begin - si := s[i]; - if si=zy then - begin - i+=2; - if i>e then return 0; - continue; - end - if s[i]=c then //找到了 - begin - return i; - end - i++; - end - return 0; //没找到 - for i := b to e do - begin - if s[i]=c then //找到了 - begin - return i; - end - end - + ExecuteCommand("string",array(('"',"\\"))); + ExecuteCommand("keywords",array("object","end")); + ExecuteCommand("rowannotes",array()); + ExecuteCommand("blockannotes",array()); + ExecuteCommand("syms",array("{","}","[","]","<",">",":",",","=")); + ExecuteCommand("pairs",array(("{","}"),("[","]"),("<",">"),("object","end"))); end - private - fdolastline; - FTokens; - FSates; - FSatesCount; - - FCBBState; - FCBEState; - FCMBState; - FBBStates; - FBEStates; - FMBStates ; - FbgedStates; - FjkhStates; - fcbgesate; - fcjkhState; end + implementation -type TBBState =class //括号状态 +type TBBState =class(tpairstate) //括号状态 function Create(t); begin - FType := ifstring(t)?t:""; - FCJ := 0; - FState := 0; - FIndexs := array(0); - FIndex := 0; - FCstate := false; + inherited; end - function GetLeft(); - begin - FCstate := true; - if FState then // 上一个是左括号 - begin - FCJ++; - FIndex++; - FIndexs[FIndex]:=0; - end else //上一个非左括号 - begin - - FIndexs[FIndex]++; - end - FState := true; - end - function GetRight(); - begin - FCstate := true; - //if FCJ=0 then return ; - if FState then // 上一个是左括号 - begin - - //FIndexs[FIndex]++; - end else //上一个非左括号 - begin - if FCJ>0 then - begin - FCJ--; - DeleteIndex(FIndexs,FIndex); - FIndex--; - end else - begin - FCstate := false; - end - end - FState := false; - end - function GetSate(); - begin - if FCstate then - begin - //return inttostr(FIndexs[FCJ])+FType; - return tostn(FIndexs)+FType;// inttostr(FCJ)+"+"+inttostr(FIndexs[FIndex])+FType; length(FIndexs)+FType ;// - end - end - function Show(); - begin - echo "层级:",FCJ," 序号:",FIndexs[FIndex],"状态:", FCstate; - end - function Clone(); - begin - r := new TBBState(FType); - r.FCstate := FCstate; - r.FState := FState; - r.FCJ := FCJ; - r.FIndexs := FIndexs; - r.FIndex := FIndex; - return r; - end - protected - FCstate; - FState; - FCJ; - FIndexs; - FIndex; - FType; - end type TTsfFileParser = class //文件解析 private diff --git a/funcext/tvclib/utslmemo.tsf b/funcext/tvclib/utslmemo.tsf index 1a272b4..114331c 100644 --- a/funcext/tvclib/utslmemo.tsf +++ b/funcext/tvclib/utslmemo.tsf @@ -3014,6 +3014,450 @@ type TSynHighLighter = class(TComponent) // Flines; FMemo; +end +type tcustomsynhighlighter = class(TSynHighLighter) +{** + @explan(说明) 通用的语法高亮类 + 支持单行注释,块注释,配对,字符串定义,关键字,符号%% + @data(20220915) +**} + function create(AOwner); + begin + inherited; + fsymcolor := 0xa000a0; + fkeywordcolor := 0x0000ff; + fstringcolor := 0xff00ff; + fannotationcolor := 0xff0000; + fignorecase := false;//忽略大小写 + FChangeDeal := true; + FTokens := array(); + setkeyword(array("null","true","false")); + setblockannote(array( + ("/*","*/"), + )); + setrowannote(array("//")); + setsyms(array("+","-","*","/",";","(",")","{","}",":")); + setstring(array( + ("'","\\"), + ('"',"\\"), + )); + setpairs(array( + ("(",")"), + ("{","}"), + )); + clean(); + end + function ExecuteCommand(cmd,pm);override; + begin + {** + @explan(说明) 对外接口 %% + @param(cmd)(string) 命令%% + @param(pm)(array) 参数 %% + **} + case cmd of + "strings": + begin + return setstring(pm); + end + "rowannotes": + begin + return setrowannote(pm); + end + "blockannotes": + begin + return setblockannote(pm); + end + "keywords": + begin + return setkeyword(pm); + end + "syms": + begin + return setsyms(pm); + end + "pairs": + begin + return setpairs(pm); + end + end ; + return inherited; + end + function SetInValidateIndex(idx);override; //当前改变的行 + begin + idx := max(1,idx); + fdolastline := idx-2; + if not(FChangeDeal)and idx>FSatesCount then return; + if length(FSates)>= idx then FSatesCount := idx; + else FSatesCount := length(FSates)-1; + if FSatesCount=1 then clean(); + FChangeDeal := false; + end + + function InsureTokenParserd(LastLine);override; //解析 + begin + ls := Lines; + FChangeDeal := true; + if fdolastline>=LastLine then return ; + fdolastline := LastLine; + for i := FSatesCount-1 to LastLine do + begin + if i<0 then continue; + s := ls.GetStringByIndex(i); + cst := FSates[i]; + tks := array(); + fcbgestate := array(); + for jj,j in mrows(Fbgedstates,1) do + begin + v := Fbgedstates[j][i]; + vj := v.Clone; + fcbgestate[j]:= vj; + Fbgedstates[j][i+1]:= vj; + end + FSates[i+1]:= ParserTokenLines(s,1,length(s),cst,tks); + FSatesCount := i+1; + FTokens[i]:= tks; + end + end + function GetLineTokens(idx);override; + begin + if idxe then return cst; + if ifarray(cst) and (cst[0]="str" or cst[0]="annote") then + begin + cst1 := cst[1]; + cstL := length(cst1); + r := FindRightChar(cst[2],s,b,e,cst[3]); + if r=0 then //没找到 + begin + Setttoken(tokens,s[b:],e,cst); + return cst; + end else //找到 + if r <= e then + begin + if be then return 0; + continue; + end + if vo.find(s,e,i,oidx,ostr) then + begin + return i; + end + i++; + end + return 0; //没找到 + end + + private + FSatesCount ;// 状态行号 + FChangeDeal;//改变flag + fignorecase; //忽略大小写 + //前后匹配 + Fbgedstates; + fcbgestate;//当前匹配 + + /// + FSates; //当前状态 + FTokens; + fdolastline; //已经处理到行 + + + ///////tire树///////////// + fkeystires; + fstrstires; + fstrstires_zy; + fsymstires; + frowstires; + fblockstiresa; + fblockstiresb; + ///// + fkeywordcolor; + fstringcolor; + fannotationcolor; + fsymcolor; + + // + fswordpairs; + fswordpairshash; + end type TSynCustomMemo = class(TCustomMemo) {** diff --git a/funcext/tvclib/utslvclauxiliary.tsf b/funcext/tvclib/utslvclauxiliary.tsf index 40a5566..23d3669 100644 --- a/funcext/tvclib/utslvclauxiliary.tsf +++ b/funcext/tvclib/utslvclauxiliary.tsf @@ -1695,6 +1695,84 @@ type TTire = class end FRoot; end +type tpairstate =class //括号状态 + function Create(t); + begin + FType := ifstring(t)?t:""; + FCJ := 0; + FState := 0; + FIndexs := array(0); + FIndex := 0; + FCstate := false; + end + function GetLeft(); + begin + FCstate := true; + if FState then // 上一个是左括号 + begin + FCJ++; + FIndex++; + FIndexs[FIndex]:=0; + end else //上一个非左括号 + begin + + FIndexs[FIndex]++; + end + FState := true; + end + function GetRight(); + begin + FCstate := true; + //if FCJ=0 then return ; + if FState then // 上一个是左括号 + begin + + //FIndexs[FIndex]++; + end else //上一个非左括号 + begin + if FCJ>0 then + begin + FCJ--; + DeleteIndex(FIndexs,FIndex); + FIndex--; + end else + begin + FCstate := false; + end + end + FState := false; + end + function GetSate(); + begin + if FCstate then + begin + //return inttostr(FIndexs[FCJ])+FType; + return tostn(FIndexs)+FType;// inttostr(FCJ)+"+"+inttostr(FIndexs[FIndex])+FType; length(FIndexs)+FType ;// + end + end + function Show(); + begin + echo "层级:",FCJ," 序号:",FIndexs[FIndex],"状态:", FCstate; + end + function Clone(); + begin + r := new tpairstate(FType); + r.FCstate := FCstate; + r.FState := FState; + r.FCJ := FCJ; + r.FIndexs := FIndexs; + r.FIndex := FIndex; + return r; + end + protected + FCstate; + FState; + FCJ; + FIndexs; + FIndex; + FType; + +end implementation function includestate(u,s); begin