📄 psvphpscript.pas
字号:
{*******************************************************}
{ RichEdit Syntax HighLight }
{ version 3.0 }
{ Author: }
{ Serhiy Perevoznyk }
{ serge_perevoznyk@hotmail.com }
{ }
{*******************************************************}
{The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: SynHighlighterPHP.pas, released 2000-04-21.
The Original Code is based on the wmPHPSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Willo van der Merwe.
All Rights Reserved.
The Original Code can be obtained from http://synedit.sourceforge.net/
}
unit psvPHPScript;
interface
uses
SysUtils,
Windows,
Messages,
Classes,
Controls,
Graphics,
psvRichSyntax;
type
TtkTokenKind = (tkComment, tkIdentifier, tkInvalidSymbol, tkKey, tkNull,
tkNumber, tkSpace, tkString, tkSymbol, tkUnknown, tkVariable);
TRangeState = (rsUnKnown, rsString39, rsString34, rsComment);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
type
TpsvPHPRTF = class(TpsvRTFSyntax)
private
fRange: TRangeState;
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
fIdentFuncTable: array[0..206] of TIdentFuncTableFunc;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
function Func15: TtkTokenKind;
function Func18: TtkTokenKind;
function Func19: TtkTokenKind;
function Func28: TtkTokenKind;
function Func31: TtkTokenKind;
function Func33: TtkTokenKind;
function Func36: TtkTokenKind;
function Func37: TtkTokenKind;
function Func38: TtkTokenKind;
function Func39: TtkTokenKind;
function Func40: TtkTokenKind;
function Func41: TtkTokenKind;
function Func42: TtkTokenKind;
function Func43: TtkTokenKind;
function Func49: TtkTokenKind;
function Func54: TtkTokenKind;
function Func55: TtkTokenKind;
function Func56: TtkTokenKind;
function Func57: TtkTokenKind;
function Func58: TtkTokenKind;
function Func59: TtkTokenKind;
function Func60: TtkTokenKind;
function Func62: TtkTokenKind;
function Func63: TtkTokenKind;
function Func64: TtkTokenKind;
function Func68: TtkTokenKind;
function Func69: TtkTokenKind;
function Func71: TtkTokenKind;
function Func72: TtkTokenKind;
function Func77: TtkTokenKind;
function Func78: TtkTokenKind;
function Func79: TtkTokenKind;
function Func80: TtkTokenKind;
function Func82: TtkTokenKind;
function Func87: TtkTokenKind;
function Func91: TtkTokenKind;
function Func93: TtkTokenKind;
function Func96: TtkTokenKind;
function Func101: TtkTokenKind;
function Func102: TtkTokenKind;
function Func105: TtkTokenKind;
function Func151: TtkTokenKind;
function Func156: TtkTokenKind;
function Func164: TtkTokenKind;
function Func177: TtkTokenKind;
function Func206: TtkTokenKind;
procedure AndSymbolProc;
procedure AsciiCharProc;
procedure AtSymbolProc;
procedure BraceCloseProc;
procedure BraceOpenProc;
procedure CRProc;
procedure ColonProc;
procedure CommaProc;
procedure EqualProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure MinusProc;
procedure MultiplyProc;
procedure NotSymbolProc;
procedure NullProc;
procedure NumberProc;
procedure OrSymbolProc;
procedure PlusProc;
procedure PointProc;
procedure PoundProc;
procedure QuestionProc;
procedure RemainderSymbolProc;
procedure RoundCloseProc;
procedure RoundOpenProc;
procedure SemiColonProc;
procedure SlashProc;
procedure SpaceProc;
procedure SquareCloseProc;
procedure SquareOpenProc;
procedure StringProc;
procedure TildeProc;
procedure VariableProc;
procedure XOrSymbolProc;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure AnsiCProc;
procedure String39Proc;
procedure String34Proc;
protected
function GetEOL: Boolean; override;
function GetRange: Pointer;
function GetTokenID: TtkTokenKind;
procedure SetLine(NewValue: String; LineNumber: Integer); override;
function GetToken: String; override;
function GetTokenAttribute: integer; override;
function GetTokenKind: integer;
function GetTokenPos: Integer;
procedure Next; override;
procedure SetRange(Value: Pointer);
procedure ResetRange;
public
constructor Create; override;
procedure SetupDefaultColors; override;
end;
implementation
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
procedure MakeIdentTable;
var
I, J: Char;
begin
for I := #0 to #255 do
begin
Case I of
'_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
else Identifiers[I] := False;
end;
J := UpCase(I);
Case I in ['_', 'A'..'Z', 'a'..'z'] of
True: mHashTable[I] := Ord(J) - 64
else mHashTable[I] := 0;
end;
end;
end;
procedure TpsvPHPRTF.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := AltFunc;
Inc(pF);
end;
fIdentFuncTable[15] := Func15;
fIdentFuncTable[18] := Func18;
fIdentFuncTable[19] := Func19;
fIdentFuncTable[28] := Func28;
fIdentFuncTable[31] := Func31;
fIdentFuncTable[33] := Func33;
fIdentFuncTable[36] := Func36;
fIdentFuncTable[37] := Func37;
fIdentFuncTable[38] := Func38;
fIdentFuncTable[39] := Func39;
fIdentFuncTable[40] := Func40;
fIdentFuncTable[41] := Func41;
fIdentFuncTable[42] := Func42;
fIdentFuncTable[43] := Func43;
fIdentFuncTable[49] := Func49;
fIdentFuncTable[54] := Func54;
fIdentFuncTable[55] := Func55;
fIdentFuncTable[56] := Func56;
fIdentFuncTable[57] := Func57;
fIdentFuncTable[58] := Func58;
fIdentFuncTable[59] := Func59;
fIdentFuncTable[60] := Func60;
fIdentFuncTable[62] := Func62;
fIdentFuncTable[63] := Func63;
fIdentFuncTable[64] := Func64;
fIdentFuncTable[68] := Func68;
fIdentFuncTable[69] := Func69;
fIdentFuncTable[71] := Func71;
fIdentFuncTable[72] := Func72;
fIdentFuncTable[77] := Func77;
fIdentFuncTable[78] := Func78;
fIdentFuncTable[79] := Func79;
fIdentFuncTable[80] := Func80;
fIdentFuncTable[82] := Func82;
fIdentFuncTable[87] := Func87;
fIdentFuncTable[91] := Func91;
fIdentFuncTable[93] := Func93;
fIdentFuncTable[96] := Func96;
fIdentFuncTable[101] := Func101;
fIdentFuncTable[102] := Func102;
fIdentFuncTable[105] := Func105;
fIdentFuncTable[151] := Func151;
fIdentFuncTable[156] := Func156;
fIdentFuncTable[164] := Func164;
fIdentFuncTable[177] := Func177;
fIdentFuncTable[206] := Func206;
end;
function TpsvPHPRTF.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['_', '0'..'9', 'a'..'z', 'A'..'Z'] do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end;
function TpsvPHPRTF.KeyComp(const aKey: String): Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end;
function TpsvPHPRTF.Func15: TtkTokenKind;
begin
if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func18: TtkTokenKind;
begin
if KeyComp('die') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func19: TtkTokenKind;
begin
if KeyComp('and') then Result := tkKey else
if KeyComp('do') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func28: TtkTokenKind;
begin
if KeyComp('case') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func31: TtkTokenKind;
begin
if KeyComp('echo') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func33: TtkTokenKind;
begin
if KeyComp('or') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func36: TtkTokenKind;
begin
if KeyComp('real') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func37: TtkTokenKind;
begin
if KeyComp('break') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func38: TtkTokenKind;
begin
if KeyComp('endif') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func39: TtkTokenKind;
begin
if KeyComp('for') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func40: TtkTokenKind;
begin
if KeyComp('eval') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func41: TtkTokenKind;
begin
if KeyComp('var') then Result := tkKey else
if KeyComp('else') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func42: TtkTokenKind;
begin
if KeyComp('new') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func43: TtkTokenKind;
begin
if KeyComp('false') then Result := tkKey else
if KeyComp('int') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func49: TtkTokenKind;
begin
if KeyComp('global') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func54: TtkTokenKind;
begin
if KeyComp('float') then Result := tkKey else
if KeyComp('class') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func55: TtkTokenKind;
begin
if KeyComp('object') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func56: TtkTokenKind;
begin
if KeyComp('elseif') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func57: TtkTokenKind;
begin
if KeyComp('while') then Result := tkKey else
if KeyComp('xor') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func58: TtkTokenKind;
begin
if KeyComp('exit') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func59: TtkTokenKind;
begin
if KeyComp('double') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func60: TtkTokenKind;
begin
if KeyComp('list') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func62: TtkTokenKind;
begin
if KeyComp('endfor') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func63: TtkTokenKind;
begin
if KeyComp('array') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func64: TtkTokenKind;
begin
if KeyComp('true') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func68: TtkTokenKind;
begin
if KeyComp('include') then Result := tkKey else Result := tkIdentifier;
end;
function TpsvPHPRTF.Func69: TtkTokenKind;
begin
if KeyComp('default') then Result := tkKey else Result := tkIdentifier;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -