📄 jvhleditor.pas
字号:
i: Integer;
const
Symbols = [',', ':', ';', '.', '[', ']', '(', ')', '=', '+',
'-', '/', '<', '>', '%', '*', '~', '''', '\', '^', '@', '{', '}',
'#', '|', '&'];
const
DelphiKeyWords =
' constructor destructor string record procedure with of' +
' repeat until try finally except for to downto case' +
' type interface implementation initialization finalization' +
' default private public protected published automated property' +
' program read write override object nil raise' +
' on set xor shr shl begin end args if then else' +
' endif goto while do var or and not mod div unit' +
' function uses external const class inherited' +
' register stdcall cdecl safecall pascal is as package program' +
' external overload platform deprecated implements export contains' +
' requires resourcestring';
BuilderKeyWords =
' __asm _asm asm auto __automated break bool case catch __cdecl' +
' _cdecl cdecl char class __classid __closure const const_cast' +
' continue __declspec default delete __dispid do double dynamic_cast' +
' else enum __except explicit _export __export extern false __fastcall' +
' _fastcall __finally float for friend goto if __import _import inline' +
' int __int8 __int16 __int32 __int64 long mutable namespace new operator' +
' __pascal _pascal pascal private protected __property public __published' +
' register reinterpret_cast return __rtti short signed sizeof static static_cast' +
' __stdcall _stdcall struct switch template this __thread throw true __try' +
' try typedef typename typeid union using unsigned virtual void volatile' +
' wchar_t while ';
NQCKeyWords: string = {Not Quite C - a C similar language for programming LEGO MindStorm(R) robots }
' __event_src __type acquire break __sensor abs asm case catch const' +
' continue default do else false for if inline' +
' int monitor repeat return signed start stop sub switch task true' +
' until void while ';
SQLKeyWords: string =
' active as add asc after ascending all at alter auto' +
' and autoddl any avg based between basename blob' +
' base_name blobedit before buffer begin by cache compiletime' +
' cast computed char close character conditional character_length connect' +
' char_length constraint check containing check_point_len continue check_point_length count' +
' collate create collation cstring column current commit cursor' +
' committed database descending date describe db_key descriptor debug disconnect' +
' dec display decimal distinct declare do default domain' +
' delete double desc drop echo exception edit execute' +
' else exists end exit entry_point extern escape external' +
' event extract fetch foreign file found filter from' +
' float full for function gdscode grant generator group' +
' gen_id commit_group_wait global group_commit_wait_time goto' +
' having help if input_type immediate insert in int' +
' inactive integer index into indicator is init isolation' +
' inner isql input join key' +
' lc_messages like lc_type logfile left log_buffer_size length log_buf_size' +
' lev long level manual merge max message' +
' maximum min maximum_segment minimum max_segment module_name names not' +
' national null natural numeric nchar num_log_bufs no num_log_buffers' +
' noauto octet_length or of order on outer only output' +
' open output_type option overflow page post_event pagelength precision' +
' pages prepare page_size procedure parameter protected password primary' +
' plan privileges position public quit' +
' raw_partitions retain rdb db_key return read returning_values real returns' +
' record_version revoke references right release rollback reserv runtime' +
' reserving schema sql segment sqlcode select sqlerror set sqlwarning' +
' shadow stability shared starting shell starts show statement' +
' singular static size statistics smallint sub_type snapshot sum' +
' some suspend sort table translate terminator translation then trigger to trim' +
' transaction uncommitted upper union user unique using update' +
' value varying values version varchar view variable' +
' wait while when with whenever work where write' +
' term new old ';
PythonKeyWords =
' and del for is raise' +
' assert elif from lambda return' +
' break else global not try' +
' class except if or while' +
' continue exec import pass' +
' def finally in print ';
JavaKeyWords =
' abstract delegate if boolean do implements break double import' +
' byte else instanceof case extends int catch false interface' +
' char final long class finally multicast continue float' +
' default for native short transient new static true' +
' null super try package switch void private synchronized volatile' +
' protected this while public throw return throws ';
VBKeyWords =
' as and base binary byref byval call case class compare const date debug declare deftype dim do each else elseif ' +
' empty end endif enum eqv erase error event execute exit explicit false for friend function get' +
' global gosub goto if imp implements input is kill len let line load lock loop lset me mid mod name new next not nothing null on open option optional' +
' or paramarray preserve print private property public raiseevent randomize redim rem' +
' resume return seek select set static step' +
' string sub then time to true unlock until wend while with withevents xor ';
VBStatements =
' access alias any beep ccur cdbl chdir chdrive choose' +
' chr cint clear clng clone close cls command compare' +
' cos csng cstr curdir currency cvar cvdate ' +
' defcur defdbl defint deflng defsng defstr deftype defvar delete deletesetting' +
' doevents double dynaset edit environ eof erl err exp fix format ' +
' hex int integer isdate isempty isnull isnumeric lbound lcase' +
' lib like loc local lof long mkdir oct output pset put' +
' random read refresh reset restore rmdir rnd rset savesetting ' +
' sendkeys shared single stop system text type typeof ubound unload ' +
' using variant vartype write';
HTMLTags =
' doctype a address applet area b base basefont bgsound big blink ' +
' blockquote body br caption center cite code col colgroup comment ' +
' dfn dir li div dl dt dd em embed font form frame frameset h align ' +
' h1 h2 h3 h4 h5 h6 head hr html i iframe img input isindex kbd link ' +
' listing map marquee menu meta multicol nextid nobr noframes noscript ' +
' object ol option p plaintext pre s samp script select small sound ' +
' spacer span strike strong style sub sup table tbody td textarea tfoot' +
' th thead title tr tt u ul var wbr xmp ';
HtmlSpecChars =
' Aacute aacute acirc Acirc acute AElig aelig agrave Agrave alefsym ' +
' alpha Alpha AMP amp and ang Aring aring asymp atilde Atilde Auml ' +
' auml bdquo beta Beta brvbar bull cap Ccedil ccedil cedil cent chi ' +
' Chi circ clubs cong copy COPY crarr cup curren dagger Dagger dArr ' +
' darr deg Delta delta diams divide eacute Eacute ecirc Ecirc Egrave ' +
' egrave empty emsp ensp Epsilon epsilon equiv eta Eta ETH eth Euml ' +
' euml euro exist fnof forall frac12 frac14 frac34 frasl Gamma gamma ' +
' ge gt GT harr hArr hearts hellip iacute Iacute Icirc icirc iexcl Igrave ' +
' igrave image infin int Iota iota iquest isin Iuml iuml kappa Kappa Lambda ' +
' lambda lang laquo larr lArr lceil ldquo le lfloor lowast loz lrm lsaquo ' +
' lsquo lt LT macr mdash micro middot minus mu Mu nabla nbsp ndash ne ' +
' ni not notin nsub Ntilde ntilde Nu nu oacute Oacute ocirc Ocirc oelig ' +
' OElig ograve Ograve oline Omega omega omicron Omicron oplus or ordf ' +
' ordm Oslash oslash Otilde otilde otimes ouml Ouml para part permil ' +
' perp phi Phi Pi pi piv plusmn pound Prime prime prod prop psi Psi quot ' +
' QUOT radic rang raquo rArr rarr rceil rdquo real REG reg rfloor Rho ' +
' rho rlm rsaquo rsquo sbquo scaron Scaron sdot sect shy Sigma sigma ' +
' sigmaf sim spades sub sube sum sup sup1 sup2 sup3 supe szlig Tau ' +
' tau there4 Theta theta thetasym thinsp THORN thorn tilde times trade ' +
' Uacute uacute uArr uarr ucirc Ucirc ugrave Ugrave uml upsih upsilon ' +
' Upsilon uuml Uuml weierp xi Xi Yacute yacute yen yuml Yuml zeta Zeta ' +
' zwj zwnj ';
PerlKeyWords =
' sub if else unless foreach next local ' +
' return defined until while do elsif eq ';
PerlStatements =
' stat die open print push close defined chdir last read chop ' +
' keys sort bind unlink select length ';
CocoKeyWords = DelphiKeyWords +
' compiler productions delphi end_delphi ignore case characters ' +
' tokens create destroy errors comments from nested chr any ' +
' description ';
function PosI(const S1, S2: string): Boolean;
var
F, P: PChar;
Len: Integer;
begin
Len := Length(S1);
Result := True;
P := PChar(S2);
while P[0] <> #0 do
begin
while P[0] = ' ' do Inc(P);
F := P;
while not (P[0] <= #32) do Inc(P);
if (P - F) = Len then
if StrLIComp(Pointer(S1), F, Len) = 0 then Exit;
end;
Result := False;
end;
function PosNI(const S1, S2: string): Boolean;
var
F, P: PChar;
Len: Integer;
begin
Len := Length(S1);
Result := True;
P := PChar(S2);
while P[0] <> #0 do
begin
while P[0] = ' ' do Inc(P);
F := P;
while not (P[0] <= #32) do Inc(P);
if (P - F) = Len then
if StrLComp(Pointer(S1), F, Len) = 0 then Exit;
end;
Result := False;
end;
function IsDelphiKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + AnsiLowerCase(St) + ' ', DelphiKeyWords) <> 0;
Result := PosI(St, DelphiKeyWords);
end;
function IsBuilderKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + St + ' ', BuilderKeyWords) <> 0;
Result := PosNI(St, BuilderKeyWords);
end;
function IsNQCKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + St + ' ', NQCKeyWords) <> 0;
Result := PosNI(St, NQCKeyWords);
end;
function IsJavaKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + St + ' ', JavaKeyWords) <> 0;
Result := PosNI(St, JavaKeyWords);
end;
function IsVBKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + LowerCase(St) + ' ', VBKeyWords) <> 0;
Result := PosI(St, VBKeyWords);
end;
function IsVBStatement(const St: string): Boolean;
begin
// Result := Pos(' ' + LowerCase(St) + ' ', VBStatements) <> 0;
Result := PosI(St, VBStatements);
end;
function IsSQLKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + AnsiLowerCase(St) + ' ', SQLKeyWords) <> 0;
Result := PosI(St, SQLKeyWords);
end;
function IsPythonKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + St + ' ', PythonKeyWords) <> 0;
Result := PosNI(St, PythonKeyWords);
end;
function IsHtmlTag(const St: string): Boolean;
begin
// Result := Pos(' ' + AnsiLowerCase(St) + ' ', HtmlTags) <> 0;
Result := PosI(St, HtmlTags);
end;
function IsHtmlSpecChar(const St: string): Boolean;
begin
// Result := Pos(' ' + AnsiLowerCase(St) + ' ', HtmlSpecChars) <> 0;
Result := PosI(St, HtmlSpecChars);
end;
function IsPerlKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + St + ' ', PerlKeyWords) <> 0;
Result := PosNI(St, PerlKeyWords);
end;
function IsPerlStatement(const St: string): Boolean;
begin
// Result := Pos(' ' + St + ' ', PerlStatements) <> 0;
Result := PosNI(St, PerlStatements);
end;
function IsCocoKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + AnsiLowerCase(St) + ' ', CocoKeyWords) <> 0;
Result := PosI(St, CocoKeyWords);
end;
function IsPhpKeyWord(const St: string): Boolean;
begin
// Result := Pos(' ' + St + ' ', PerlKeyWords) <> 0;
Result := PosNI(St, PerlKeyWords);
end;
function IsComment(const St: string): Boolean;
var
LS: Integer;
begin
LS := Length(St);
case HighLighter of
hlPascal:
Result := ((LS > 0) and (St[1] = '{')) or
((LS > 1) and (((St[1] = '(') and (St[2] = '*')) or
((St[1] = '/') and (St[2] = '/'))));
hlCBuilder, hlSQL, hlJava, hlPhp, hlNQC:
Result := (LS > 1) and (St[1] = '/') and
((St[2] = '*') or (St[2] = '/'));
hlVB:
Result := (LS > 0) and (St[1] = '''');
hlPython, hlPerl:
Result := (LS > 0) and (St[1] = '#');
hlIni:
Result := (LS > 0) and (St[1] in ['#', ';']);
hlCocoR:
Result := (LS > 1) and (((St[1] = '/') and (St[2] = '/')) or
((St[1] = '(') and (St[2] = '*')) or
((St[1] = '/') and (St[2] = '*'))
);
else
Result := False;
end;
end;
function IsStringConstant(const St: string): Boolean;
var
LS: Integer;
begin
LS := Length(St);
case FHighLighter of
hlPascal, hlCBuilder, hlSql, hlPython, hlJava, hlPerl, hlCocoR, hlPhp, hlNQC:
Result := (LS > 0) and ((St[1] = '''') or (St[1] = '"'));
hlVB:
Result := (LS > 0) and (St[1] = '"');
hlHtml:
Result := False;
else
Result := False; { unknown highlighter ? }
end;
end;
procedure SetBlockColor(iBeg, iEnd: Integer; Color: TJvSymbolColor);
var
I: Integer;
begin
if iEnd > Max_X then iEnd := Max_X;
for I := iBeg to iEnd do
with LineAttrs[I] do
begin
FC := Color.ForeColor;
BC := Color.BackColor;
Style := Color.Style;
end;
end;
procedure SetColor(Color: TJvSymbolColor);
begin
SetBlockColor(Parser.PosBeg[0] + 1, Parser.PosEnd[0], Color);
end;
function NextSymbol: string;
var
I: Integer;
begin
I := 0;
while (Parser.PCPos[I] <> #0) and (Parser.PCPos[I] in [' ', #9, #13, #10]) do
Inc(I);
Result := Parser.PCPos[I];
end;
procedure TestHtmlSpecChars;
var
i, j, iBeg, iEnd: Integer;
S1: string;
F1: Integer;
begin
i := 1;
F1 := Parser.PosBeg[0];
while i <= Length(Token) do
begin
if Token[i] = '&' then
begin
iBeg := i;
iEnd := iBeg;
Inc(i);
while i <= Length(Token) do
begin
if Token[i] = ';' then
begin
iEnd := i;
Break;
end;
Inc(i);
end;
if iEnd > iBeg + 1 then
begin
S1 := Copy(Token, iBeg + 1, iEnd - iBeg - 1);
if IsHtmlSpecChar(S1) then
for j := iBeg to iEnd do
with LineAttrs[F1 + j] do
begin
FC := Colors.Preproc.ForeColor;
BC := Colors.Preproc.BackColor;
Style := Colors.Preproc.Style;
end;
end;
end;
Inc(i);
end;
end;
var
S: string;
LS: Integer;
procedure SetIniColors;
var
EquPos: Integer;
begin
if (LS > 0) and (S[1] = '[') and (S[LS] = ']') then
SetBlockColor(0, LS, FColors.FDeclaration)
else
begin
EquPos := Pos('=', S);
if EquPos > 0 then
begin
SetBlockColor(0, EquPos, FColors.FIdentifier);
SetBlockColor(EquPos, EquPos, FColors.FSymbol);
SetBlockColor(EquPos + 1, LS, FColors.FString);
end;
end;
end;
// for Coco/R
procedure HighlightGrammarName;
var
P: Integer;
begin
P := Pos('-->Grammar<--', S);
if P > 0 then
SetBlockColor(P, P + Length('-->Grammar<--') - 1, FColors.FPreproc);
end;
// (rom) const, var, local function sequence not cleaned up yet
var
F: Boolean;
C: TJvSymbolColor;
Reserved: Boolean;
PrevToken: string;
PrevToken2: string;
NextToken: string;
InTag: Boolean;
N: Integer;
begin
if not FSyntaxHighlighting then Exit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -