编辑器
优化代码
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
unit UTslCodeFormat;
|
unit UTslCodeFormat;
|
||||||
interface
|
interface
|
||||||
|
uses utslvclauxiliary;
|
||||||
//TSL代码格式化 code 为代码,tabwidth 为缩进空格数 LineWordCount 为单行最大的词数目 linelength 字符最多个数
|
//TSL代码格式化 code 为代码,tabwidth 为缩进空格数 LineWordCount 为单行最大的词数目 linelength 字符最多个数
|
||||||
//20210311 美化了函数定义换行的问题
|
//20210311 美化了函数定义换行的问题
|
||||||
//20210406 LineWordCount linelength 两个参数已经不起作用
|
//20210406 LineWordCount linelength 两个参数已经不起作用
|
||||||
//20210308 添加 ABComment 参数,控制块注释的行首缩进
|
//20210308 添加 ABComment 参数,控制块注释的行首缩进
|
||||||
|
//20220914 移动tire树到 utslvclauxiliary
|
||||||
function FormatTsl(Code,tabwidth,LineWordCount,linelength,arraytype,ABComment);
|
function FormatTsl(Code,tabwidth,LineWordCount,linelength,arraytype,ABComment);
|
||||||
type TTslFParser = class(TFormatParser)
|
type TTslFParser = class(TFormatParser)
|
||||||
function Create();
|
function Create();
|
||||||
@@ -1460,69 +1462,7 @@ Type TTK = class
|
|||||||
FTypeSub := st ;
|
FTypeSub := st ;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
type TTire = class
|
|
||||||
type TTireNode = class
|
|
||||||
FChar;
|
|
||||||
FSub;
|
|
||||||
FEnd;
|
|
||||||
function Create(v);
|
|
||||||
begin
|
|
||||||
FChar := v;
|
|
||||||
FSub := array();
|
|
||||||
FEnd := false;
|
|
||||||
end
|
|
||||||
function Add(s);
|
|
||||||
begin
|
|
||||||
v0 := s[1];
|
|
||||||
vsub := FSub[v0];
|
|
||||||
if not vsub then
|
|
||||||
begin
|
|
||||||
vsub := new TTireNode(v0);
|
|
||||||
FSub[v0] := vsub;
|
|
||||||
end
|
|
||||||
ls := length(s);
|
|
||||||
if ls>1 then
|
|
||||||
vsub.Add(s[2:]);
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
vsub.FEnd := true;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function Find(s,slen,idx);
|
|
||||||
begin
|
|
||||||
if idx>slen then return FEnd;
|
|
||||||
v0 := s[idx];
|
|
||||||
vsub := FSub[v0];
|
|
||||||
if vsub then
|
|
||||||
begin
|
|
||||||
idx++;
|
|
||||||
return vsub.Find(s,slen,idx);
|
|
||||||
end
|
|
||||||
return FEnd ;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function Add(s);
|
|
||||||
begin
|
|
||||||
FRoot.Add(s);
|
|
||||||
end
|
|
||||||
function Create();
|
|
||||||
begin
|
|
||||||
FRoot := new TTireNode();
|
|
||||||
end
|
|
||||||
function Find(s,slen,idx,outidx,ostr);
|
|
||||||
begin
|
|
||||||
tid := idx;
|
|
||||||
r := FRoot.Find(s,slen,idx);
|
|
||||||
if r then
|
|
||||||
begin
|
|
||||||
ostr := s[tid:idx-1];
|
|
||||||
outidx := idx;
|
|
||||||
end
|
|
||||||
idx := tid;
|
|
||||||
return r;
|
|
||||||
end
|
|
||||||
FRoot;
|
|
||||||
end
|
|
||||||
Type TStateStack = class
|
Type TStateStack = class
|
||||||
function Create();
|
function Create();
|
||||||
begin
|
begin
|
||||||
|
|||||||
@@ -310,6 +310,7 @@ type TTslSynHighLighter = class(TSynHighLighter)
|
|||||||
begin
|
begin
|
||||||
idx := max(1,idx);
|
idx := max(1,idx);
|
||||||
if not(FChangeDeal) and idx>FSatesCount then return ;
|
if not(FChangeDeal) and idx>FSatesCount then return ;
|
||||||
|
fdolastline := idx-2;
|
||||||
if length(FSates)>=idx then
|
if length(FSates)>=idx then
|
||||||
FSatesCount := idx;
|
FSatesCount := idx;
|
||||||
else FSatesCount := length(FSates)-1;
|
else FSatesCount := length(FSates)-1;
|
||||||
@@ -975,7 +976,8 @@ type TTslSynHighLighter = class(TSynHighLighter)
|
|||||||
FChangeDeal := true;
|
FChangeDeal := true;
|
||||||
{setprofiler(7);
|
{setprofiler(7);
|
||||||
t := now();}
|
t := now();}
|
||||||
mtic;
|
if fdolastline>=LastLine then return ;
|
||||||
|
fdolastline := LastLine;
|
||||||
for i:= FSatesCount-1 to LastLine do
|
for i:= FSatesCount-1 to LastLine do
|
||||||
begin
|
begin
|
||||||
if i<0 then continue;
|
if i<0 then continue;
|
||||||
@@ -1114,6 +1116,7 @@ type TTslSynHighLighter = class(TSynHighLighter)
|
|||||||
static FJsHtmlEvent;
|
static FJsHtmlEvent;
|
||||||
static FCssPropertys;
|
static FCssPropertys;
|
||||||
private
|
private
|
||||||
|
fdolastline;
|
||||||
FChangeDeal;
|
FChangeDeal;
|
||||||
//语言分支
|
//语言分支
|
||||||
FSynBranch;
|
FSynBranch;
|
||||||
@@ -1256,6 +1259,7 @@ type TJsonSynHighLighter = class(TSynHighLighter)
|
|||||||
begin
|
begin
|
||||||
idx := max(1,idx);
|
idx := max(1,idx);
|
||||||
if not(FChangeDeal) and idx>FSatesCount then return ;
|
if not(FChangeDeal) and idx>FSatesCount then return ;
|
||||||
|
fdolastline := idx-2;
|
||||||
if length(FSates)>=idx then
|
if length(FSates)>=idx then
|
||||||
FSatesCount := idx;
|
FSatesCount := idx;
|
||||||
else FSatesCount := length(FSates)-1;
|
else FSatesCount := length(FSates)-1;
|
||||||
@@ -1342,6 +1346,8 @@ label L_XCDG;
|
|||||||
begin
|
begin
|
||||||
ls := Lines;
|
ls := Lines;
|
||||||
FChangeDeal := true;
|
FChangeDeal := true;
|
||||||
|
if fdolastline>=LastLine then return ;
|
||||||
|
fdolastline := LastLine;
|
||||||
for i:= FSatesCount-1 to LastLine do
|
for i:= FSatesCount-1 to LastLine do
|
||||||
begin
|
begin
|
||||||
if i<0 then continue;
|
if i<0 then continue;
|
||||||
@@ -1456,6 +1462,7 @@ label L_XCDG;
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
fdolastline;
|
||||||
FTokens;
|
FTokens;
|
||||||
FSates;
|
FSates;
|
||||||
FSatesCount;
|
FSatesCount;
|
||||||
@@ -1496,6 +1503,7 @@ type ttfmhighlighter = class(TSynHighLighter)
|
|||||||
begin
|
begin
|
||||||
idx := max(1,idx);
|
idx := max(1,idx);
|
||||||
if not(FChangeDeal) and idx>FSatesCount then return ;
|
if not(FChangeDeal) and idx>FSatesCount then return ;
|
||||||
|
fdolastline := idx-2;
|
||||||
if length(FSates)>=idx then
|
if length(FSates)>=idx then
|
||||||
FSatesCount := idx;
|
FSatesCount := idx;
|
||||||
else FSatesCount := length(FSates)-1;
|
else FSatesCount := length(FSates)-1;
|
||||||
@@ -1587,6 +1595,8 @@ label L_XCDG;
|
|||||||
begin
|
begin
|
||||||
ls := Lines;
|
ls := Lines;
|
||||||
FChangeDeal := true;
|
FChangeDeal := true;
|
||||||
|
if fdolastline>=LastLine then return ;
|
||||||
|
fdolastline := LastLine;
|
||||||
for i:= FSatesCount-1 to LastLine do
|
for i:= FSatesCount-1 to LastLine do
|
||||||
begin
|
begin
|
||||||
if i<0 then continue;
|
if i<0 then continue;
|
||||||
@@ -1727,6 +1737,7 @@ label L_XCDG;
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
fdolastline;
|
||||||
FTokens;
|
FTokens;
|
||||||
FSates;
|
FSates;
|
||||||
FSatesCount;
|
FSatesCount;
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ type tsgtkapi = class(tgtkapis)
|
|||||||
function shell32DllGetVersion();
|
function shell32DllGetVersion();
|
||||||
begin
|
begin
|
||||||
end
|
end
|
||||||
|
function GetSystemMetrics(idx);
|
||||||
|
begin
|
||||||
|
global g_w_c_width;
|
||||||
|
case idx of
|
||||||
|
0x4 : return g_w_c_width;
|
||||||
|
end ;
|
||||||
|
return 24;
|
||||||
|
end
|
||||||
function GetCursorInfo_();
|
function GetCursorInfo_();
|
||||||
begin
|
begin
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ unit utslvclauxiliary;
|
|||||||
{**
|
{**
|
||||||
@explan(说明) tslvcl 辅助库 %%
|
@explan(说明) tslvcl 辅助库 %%
|
||||||
**}
|
**}
|
||||||
|
//20220914 移入tire树
|
||||||
interface
|
interface
|
||||||
function includestate(u,s);
|
function includestate(u,s);
|
||||||
function excludestate(u,s);
|
function excludestate(u,s);
|
||||||
@@ -1628,6 +1629,72 @@ type TNode = class()
|
|||||||
return FItems.Count;
|
return FItems.Count;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
type TTire = class
|
||||||
|
{**
|
||||||
|
@explan(说明) tire树
|
||||||
|
**}
|
||||||
|
type TTireNode = class
|
||||||
|
FChar;
|
||||||
|
FSub;
|
||||||
|
FEnd;
|
||||||
|
function Create(v);
|
||||||
|
begin
|
||||||
|
FChar := v;
|
||||||
|
FSub := array();
|
||||||
|
FEnd := false;
|
||||||
|
end
|
||||||
|
function Add(s);
|
||||||
|
begin
|
||||||
|
v0 := s[1];
|
||||||
|
vsub := FSub[v0];
|
||||||
|
if not vsub then
|
||||||
|
begin
|
||||||
|
vsub := new TTireNode(v0);
|
||||||
|
FSub[v0] := vsub;
|
||||||
|
end
|
||||||
|
ls := length(s);
|
||||||
|
if ls>1 then
|
||||||
|
vsub.Add(s[2:]);
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
vsub.FEnd := true;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function Find(s,slen,idx);
|
||||||
|
begin
|
||||||
|
if idx>slen then return FEnd;
|
||||||
|
v0 := s[idx];
|
||||||
|
vsub := FSub[v0];
|
||||||
|
if vsub then
|
||||||
|
begin
|
||||||
|
idx++;
|
||||||
|
return vsub.Find(s,slen,idx);
|
||||||
|
end
|
||||||
|
return FEnd ;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function Add(s);
|
||||||
|
begin
|
||||||
|
FRoot.Add(s);
|
||||||
|
end
|
||||||
|
function Create();
|
||||||
|
begin
|
||||||
|
FRoot := new TTireNode();
|
||||||
|
end
|
||||||
|
function Find(s,slen,idx,outidx,ostr);
|
||||||
|
begin
|
||||||
|
tid := idx;
|
||||||
|
r := FRoot.Find(s,slen,idx);
|
||||||
|
if r then
|
||||||
|
begin
|
||||||
|
ostr := s[tid:idx-1];
|
||||||
|
outidx := idx;
|
||||||
|
end
|
||||||
|
idx := tid;
|
||||||
|
return r;
|
||||||
|
end
|
||||||
|
FRoot;
|
||||||
|
end
|
||||||
implementation
|
implementation
|
||||||
function includestate(u,s);
|
function includestate(u,s);
|
||||||
begin
|
begin
|
||||||
|
|||||||
Reference in New Issue
Block a user