2006-05-30 16:23:25 +02:00
|
|
|
unit uPSUtils;
|
|
|
|
{$I PascalScript.inc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes, SysUtils;
|
2008-08-01 13:23:09 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
const
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
PSMainProcName = '!MAIN';
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
PSMainProcNameOrg = 'Main Proc';
|
|
|
|
|
|
|
|
PSLowBuildSupport = 12;
|
|
|
|
|
2007-01-19 15:48:53 +01:00
|
|
|
PSCurrentBuildNo = 23;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2007-01-19 15:48:53 +01:00
|
|
|
PSCurrentversion = '1.31';
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
PSValidHeader = 1397769801;
|
|
|
|
|
|
|
|
PSAddrStackStart = 1610612736;
|
|
|
|
|
|
|
|
PSAddrNegativeStackStart = 1073741824;
|
|
|
|
type
|
2008-09-29 11:54:44 +02:00
|
|
|
TbtString = {$IFDEF DELPHI2009UP}RawByteString{$ELSE}String{$ENDIF};
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
TPSBaseType = Byte;
|
|
|
|
|
|
|
|
TPSVariableType = (ivtGlobal, ivtParam, ivtVariable);
|
|
|
|
|
|
|
|
const
|
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btReturnAddress = 0;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btU8 = 1;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btS8 = 2;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btU16 = 3;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btS16 = 4;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btU32 = 5;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btS32 = 6;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btSingle = 7;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btDouble = 8;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btExtended = 9;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btString = 10;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btRecord = 11;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btArray = 12;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btPointer = 13;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btPChar = 14;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
btResourcePointer = 15;
|
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btVariant = 16;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
{$IFNDEF PS_NOINT64}
|
|
|
|
btS64 = 17;
|
2006-05-30 16:23:25 +02:00
|
|
|
{$ENDIF}
|
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btChar = 18;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
{$IFNDEF PS_NOWIDESTRING}
|
|
|
|
btWideString = 19;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btWideChar = 20;
|
2006-05-30 16:23:25 +02:00
|
|
|
{$ENDIF}
|
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
btProcPtr = 21;
|
|
|
|
|
|
|
|
btStaticArray = 22;
|
|
|
|
|
|
|
|
btSet = 23;
|
|
|
|
|
|
|
|
btCurrency = 24;
|
|
|
|
|
|
|
|
btClass = 25;
|
|
|
|
|
|
|
|
btInterface = 26;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
btNotificationVariant = 27;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
btType = 130;
|
|
|
|
|
|
|
|
btEnum = 129;
|
|
|
|
|
|
|
|
btExtClass = 131;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function MakeHash(const s: TbtString): Longint;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
const
|
|
|
|
{ Script internal command: Assign command<br>
|
|
|
|
Command: TPSCommand;<br>
|
|
|
|
VarDest, // no data<br>
|
|
|
|
VarSrc: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
CM_A = 0;
|
|
|
|
{ Script internal command: Calculate Command<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
CalcType: Byte;<br>
|
|
|
|
<i><br>
|
|
|
|
0 = +<br>
|
|
|
|
1 = -<br>
|
|
|
|
2 = *<br>
|
|
|
|
3 = /<br>
|
|
|
|
4 = MOD<br>
|
|
|
|
5 = SHL<br>
|
|
|
|
6 = SHR<br>
|
|
|
|
7 = AND<br>
|
|
|
|
8 = OR<br>
|
|
|
|
9 = XOR<br>
|
|
|
|
</i><br>
|
|
|
|
VarDest, // no data<br>
|
|
|
|
VarSrc: TPSVariable;<br>
|
|
|
|
<br>
|
|
|
|
}
|
|
|
|
CM_CA = 1;
|
|
|
|
{ Script internal command: Push<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
CM_P = 2;
|
|
|
|
{ Script internal command: Push Var<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
CM_PV = 3;
|
|
|
|
{ Script internal command: Pop<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
}
|
|
|
|
CM_PO = 4;
|
|
|
|
{ Script internal command: Call<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
ProcNo: Longword;<br>
|
|
|
|
}
|
|
|
|
Cm_C = 5;
|
|
|
|
{ Script internal command: Goto<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
NewPosition: Longint; //relative to end of this instruction<br>
|
|
|
|
}
|
|
|
|
Cm_G = 6;
|
|
|
|
{ Script internal command: Conditional Goto<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
NewPosition: LongWord; //relative to end of this instruction<br>
|
|
|
|
Var: TPSVariable; // no data<br>
|
|
|
|
}
|
|
|
|
Cm_CG = 7;
|
|
|
|
{ Script internal command: Conditional NOT Goto<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
NewPosition: LongWord; // relative to end of this instruction<br>
|
|
|
|
Var: TPSVariable; // no data<br>
|
|
|
|
}
|
|
|
|
Cm_CNG = 8;
|
|
|
|
{ Script internal command: Ret<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
}
|
|
|
|
Cm_R = 9;
|
|
|
|
{ Script internal command: Set Stack Type<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
NewType: LongWord;<br>
|
|
|
|
OffsetFromBase: LongWord;<br>
|
|
|
|
}
|
|
|
|
Cm_ST = 10;
|
|
|
|
{ Script internal command: Push Type<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
FType: LongWord;<br>
|
|
|
|
}
|
|
|
|
Cm_Pt = 11;
|
|
|
|
{ Script internal command: Compare<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
CompareType: Byte;<br>
|
|
|
|
<i><br>
|
|
|
|
0 = >=<br>
|
|
|
|
1 = <=<br>
|
|
|
|
2 = ><br>
|
|
|
|
3 = <<br>
|
|
|
|
4 = <><br>
|
|
|
|
5 = =<br>
|
|
|
|
<i><br>
|
|
|
|
IntoVar: TPSAssignment;<br>
|
|
|
|
Compare1, Compare2: TPSAssigment;<br>
|
|
|
|
}
|
|
|
|
CM_CO = 12;
|
|
|
|
{ Script internal command: Call Var<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
Cm_cv = 13;
|
|
|
|
{ Script internal command: Set Pointer<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
VarDest: TPSVariable;<br>
|
|
|
|
VarSrc: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
cm_sp = 14;
|
|
|
|
{ Script internal command: Boolean NOT<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
cm_bn = 15;
|
|
|
|
{ Script internal command: Var Minus<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;
|
|
|
|
}
|
|
|
|
cm_vm = 16;
|
|
|
|
{ Script internal command: Set Flag<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;<br>
|
|
|
|
DoNot: Boolean;<br>
|
|
|
|
}
|
|
|
|
cm_sf = 17;
|
|
|
|
{ Script internal command: Flag Goto<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Where: Cardinal;<br>
|
|
|
|
}
|
|
|
|
cm_fg = 18;
|
|
|
|
{ Script internal command: Push Exception Handler<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
FinallyOffset,<br>
|
|
|
|
ExceptionOffset, // FinallyOffset or ExceptionOffset need to be set.<br>
|
|
|
|
Finally2Offset,<br>
|
|
|
|
EndOfBlock: Cardinal;<br>
|
|
|
|
}
|
|
|
|
cm_puexh = 19;
|
|
|
|
{ Script internal command: Pop Exception Handler<br>
|
|
|
|
Command:TPSCommand; <br>
|
|
|
|
Position: Byte;<br>
|
|
|
|
<i> 0 = end of try/finally/exception block;<br>
|
|
|
|
1 = end of first finally<br>
|
|
|
|
2 = end of except<br>
|
|
|
|
3 = end of second finally<br>
|
|
|
|
</i><br>
|
|
|
|
}
|
|
|
|
cm_poexh = 20;
|
|
|
|
{ Script internal command: Integer NOT<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Where: Cardinal;<br>
|
|
|
|
}
|
|
|
|
cm_in = 21;
|
|
|
|
{Script internal command: Set Stack Pointer To Copy<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Where: Cardinal;<br>
|
|
|
|
}
|
|
|
|
cm_spc = 22;
|
|
|
|
{Script internal command: Inc<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
cm_inc = 23;
|
|
|
|
{Script internal command: Dec<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
Var: TPSVariable;<br>
|
|
|
|
}
|
|
|
|
cm_dec = 24;
|
|
|
|
{Script internal command: nop<br>
|
|
|
|
Command: TPSCommand; <br>}
|
|
|
|
cm_nop = 255;
|
|
|
|
{ Script internal command: Pop and Goto<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
NewPosition: Longint; //relative to end of this instruction<br>
|
|
|
|
}
|
|
|
|
Cm_PG = 25;
|
|
|
|
{ Script internal command: Pop*2 and Goto<br>
|
|
|
|
Command: TPSCommand; <br>
|
|
|
|
NewPosition: Longint; //relative to end of this instruction<br>
|
|
|
|
}
|
|
|
|
Cm_P2G = 26;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
TbtU8 = Byte;
|
|
|
|
|
|
|
|
TbtS8 = ShortInt;
|
|
|
|
|
|
|
|
TbtU16 = Word;
|
|
|
|
|
|
|
|
TbtS16 = SmallInt;
|
|
|
|
|
|
|
|
TbtU32 = Cardinal;
|
|
|
|
|
|
|
|
TbtS32 = Longint;
|
|
|
|
|
|
|
|
TbtSingle = Single;
|
|
|
|
|
|
|
|
TbtDouble = double;
|
|
|
|
|
|
|
|
TbtExtended = Extended;
|
|
|
|
|
|
|
|
tbtCurrency = Currency;
|
|
|
|
|
|
|
|
{$IFNDEF PS_NOINT64}
|
|
|
|
|
|
|
|
tbts64 = int64;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
tbtchar = {$IFDEF DELPHI4UP}AnsiChar{$ELSE}CHAR{$ENDIF};
|
2006-05-30 16:23:25 +02:00
|
|
|
{$IFNDEF PS_NOWIDESTRING}
|
|
|
|
|
|
|
|
tbtwidestring = widestring;
|
|
|
|
|
|
|
|
tbtwidechar = widechar;
|
|
|
|
{$ENDIF}
|
2007-03-16 10:59:59 +01:00
|
|
|
IPointer = Cardinal;
|
2006-08-18 10:34:39 +02:00
|
|
|
TPSCallingConvention = (cdRegister, cdPascal, cdCdecl, cdStdCall, cdSafeCall);
|
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
const
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
MaxListSize = Maxint div 16;
|
|
|
|
|
|
|
|
type
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
PPointerList = ^TPointerList;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
TPointerList = array[0..MaxListSize - 1] of Pointer;
|
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
TPSList = class(TObject)
|
|
|
|
protected
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
FData: PPointerList;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
FCapacity: Cardinal;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
FCount: Cardinal;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
FCheckCount: Cardinal;
|
|
|
|
private
|
|
|
|
function GetItem(Nr: Cardinal): Pointer;
|
|
|
|
procedure SetItem(Nr: Cardinal; P: Pointer);
|
|
|
|
public
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure Recreate;
|
|
|
|
{$ENDIF}
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property Data: PPointerList read FData;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
constructor Create;
|
|
|
|
|
|
|
|
function IndexOf(P: Pointer): Longint;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
destructor Destroy; override;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property Count: Cardinal read FCount;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property Items[nr: Cardinal]: Pointer read GetItem write SetItem; default;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
function Add(P: Pointer): Longint;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure AddBlock(List: PPointerList; Count: Longint);
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure Remove(P: Pointer);
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure Delete(Nr: Cardinal);
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure DeleteLast;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure Clear; virtual;
|
|
|
|
end;
|
|
|
|
TIFList = TPSList;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
TPSStringList = class(TObject)
|
|
|
|
private
|
|
|
|
List: TPSList;
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetItem(Nr: LongInt): TbtString;
|
|
|
|
procedure SetItem(Nr: LongInt; const s: TbtString);
|
2006-05-30 16:23:25 +02:00
|
|
|
public
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
function Count: LongInt;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property Items[Nr: Longint]: TbtString read GetItem write SetItem; default;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure Add(const P: TbtString);
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure Delete(NR: LongInt);
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure Clear;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
constructor Create;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
destructor Destroy; override;
|
|
|
|
end;
|
|
|
|
TIFStringList = TPsStringList;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
TPSPasToken = (
|
|
|
|
CSTI_EOF,
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
CSTIINT_Comment,
|
|
|
|
CSTIINT_WhiteSpace,
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
CSTI_Identifier,
|
|
|
|
CSTI_SemiColon,
|
|
|
|
CSTI_Comma,
|
|
|
|
CSTI_Period,
|
|
|
|
CSTI_Colon,
|
|
|
|
CSTI_OpenRound,
|
|
|
|
CSTI_CloseRound,
|
|
|
|
CSTI_OpenBlock,
|
|
|
|
CSTI_CloseBlock,
|
|
|
|
CSTI_Assignment,
|
|
|
|
CSTI_Equal,
|
|
|
|
CSTI_NotEqual,
|
|
|
|
CSTI_Greater,
|
|
|
|
CSTI_GreaterEqual,
|
|
|
|
CSTI_Less,
|
|
|
|
CSTI_LessEqual,
|
|
|
|
CSTI_Plus,
|
|
|
|
CSTI_Minus,
|
|
|
|
CSTI_Divide,
|
|
|
|
CSTI_Multiply,
|
|
|
|
CSTI_Integer,
|
|
|
|
CSTI_Real,
|
|
|
|
CSTI_String,
|
|
|
|
CSTI_Char,
|
|
|
|
CSTI_HexInt,
|
|
|
|
CSTI_AddressOf,
|
|
|
|
CSTI_Dereference,
|
|
|
|
CSTI_TwoDots,
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
CSTII_and,
|
|
|
|
CSTII_array,
|
|
|
|
CSTII_begin,
|
|
|
|
CSTII_case,
|
|
|
|
CSTII_const,
|
|
|
|
CSTII_div,
|
|
|
|
CSTII_do,
|
|
|
|
CSTII_downto,
|
|
|
|
CSTII_else,
|
|
|
|
CSTII_end,
|
|
|
|
CSTII_for,
|
|
|
|
CSTII_function,
|
|
|
|
CSTII_if,
|
|
|
|
CSTII_in,
|
|
|
|
CSTII_mod,
|
|
|
|
CSTII_not,
|
|
|
|
CSTII_of,
|
|
|
|
CSTII_or,
|
|
|
|
CSTII_procedure,
|
|
|
|
CSTII_program,
|
|
|
|
CSTII_repeat,
|
|
|
|
CSTII_record,
|
|
|
|
CSTII_set,
|
|
|
|
CSTII_shl,
|
|
|
|
CSTII_shr,
|
|
|
|
CSTII_then,
|
|
|
|
CSTII_to,
|
|
|
|
CSTII_type,
|
|
|
|
CSTII_until,
|
|
|
|
CSTII_uses,
|
|
|
|
CSTII_var,
|
|
|
|
CSTII_while,
|
|
|
|
CSTII_with,
|
|
|
|
CSTII_xor,
|
|
|
|
CSTII_exit,
|
|
|
|
CSTII_class,
|
|
|
|
CSTII_constructor,
|
|
|
|
CSTII_destructor,
|
|
|
|
CSTII_inherited,
|
|
|
|
CSTII_private,
|
|
|
|
CSTII_public,
|
|
|
|
CSTII_published,
|
|
|
|
CSTII_protected,
|
|
|
|
CSTII_property,
|
|
|
|
CSTII_virtual,
|
|
|
|
CSTII_override,
|
|
|
|
//CSTII_default, //Birb
|
|
|
|
CSTII_As,
|
|
|
|
CSTII_Is,
|
|
|
|
CSTII_Unit,
|
|
|
|
CSTII_Try,
|
|
|
|
CSTII_Except,
|
|
|
|
CSTII_Finally,
|
|
|
|
CSTII_External,
|
|
|
|
CSTII_Forward,
|
|
|
|
CSTII_Export,
|
|
|
|
CSTII_Label,
|
|
|
|
CSTII_Goto,
|
|
|
|
CSTII_Chr,
|
|
|
|
CSTII_Ord,
|
|
|
|
CSTII_Interface,
|
|
|
|
CSTII_Implementation,
|
2006-08-18 10:34:39 +02:00
|
|
|
CSTII_initialization, //* Nvds
|
|
|
|
CSTII_finalization, //* Nvds
|
2006-05-30 16:23:25 +02:00
|
|
|
CSTII_out,
|
|
|
|
CSTII_nil
|
|
|
|
);
|
2006-08-18 10:34:39 +02:00
|
|
|
|
|
|
|
TPSParserErrorKind = (iNoError
|
|
|
|
, iCommentError
|
|
|
|
, iStringError
|
|
|
|
, iCharError
|
|
|
|
, iSyntaxError
|
2006-05-30 16:23:25 +02:00
|
|
|
);
|
|
|
|
TPSParserErrorEvent = procedure (Parser: TObject; Kind: TPSParserErrorKind) of object;
|
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
TPSPascalParser = class(TObject)
|
|
|
|
protected
|
2008-08-01 13:23:09 +02:00
|
|
|
FData: TbtString;
|
|
|
|
FText: {$IFDEF DELPHI4UP}PAnsiChar{$ELSE}PChar{$ENDIF};
|
2006-05-30 16:23:25 +02:00
|
|
|
FLastEnterPos, FRow, FRealPosition, FTokenLength: Cardinal;
|
|
|
|
FTokenId: TPSPasToken;
|
2008-08-01 13:23:09 +02:00
|
|
|
FToken: TbtString;
|
|
|
|
FOriginalToken: TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
FParserError: TPSParserErrorEvent;
|
|
|
|
FEnableComments: Boolean;
|
|
|
|
FEnableWhitespaces: Boolean;
|
|
|
|
function GetCol: Cardinal;
|
|
|
|
// only applicable when Token in [CSTI_Identifier, CSTI_Integer, CSTI_Real, CSTI_String, CSTI_Char, CSTI_HexInt]
|
|
|
|
public
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property EnableComments: Boolean read FEnableComments write FEnableComments;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property EnableWhitespaces: Boolean read FEnableWhitespaces write FEnableWhitespaces;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure Next; virtual;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property GetToken: TbtString read FToken;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property OriginalToken: TbtString read FOriginalToken;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property CurrTokenPos: Cardinal read FRealPosition;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property CurrTokenID: TPSPasToken read FTokenId;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property Row: Cardinal read FRow;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property Col: Cardinal read GetCol;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure SetText(const Data: TbtString); virtual;
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property OnParserError: TPSParserErrorEvent read FParserError write FParserError;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function FloatToStr(E: Extended): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function FastLowerCase(const s: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function Fw(const S: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function IntToStr(I: LongInt): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function StrToIntDef(const S: TbtString; Def: LongInt): LongInt;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function StrToInt(const S: TbtString): LongInt;
|
|
|
|
function StrToFloat(const s: TbtString): Extended;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function FastUpperCase(const s: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function GRFW(var s: TbtString): TbtString;
|
|
|
|
function GRLW(var s: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
const
|
2007-03-16 10:59:59 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
FCapacityInc = 32;
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
FMaxCheckCount = (FCapacityInc div 4) * 64;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$IFDEF DELPHI3UP }
|
|
|
|
resourceString
|
|
|
|
{$ELSE }
|
|
|
|
const
|
|
|
|
{$ENDIF }
|
|
|
|
RPS_InvalidFloat = 'Invalid float';
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function MakeHash(const s: TbtString): Longint;
|
2006-05-30 16:23:25 +02:00
|
|
|
{small hash maker}
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
for I := 1 to Length(s) do
|
|
|
|
Result := ((Result shl 7) or (Result shr 25)) + Ord(s[I]);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function GRFW(var s: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
l: Longint;
|
|
|
|
begin
|
|
|
|
l := 1;
|
|
|
|
while l <= Length(s) do
|
|
|
|
begin
|
|
|
|
if s[l] = ' ' then
|
|
|
|
begin
|
|
|
|
Result := copy(s, 1, l - 1);
|
|
|
|
Delete(s, 1, l);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
l := l + 1;
|
|
|
|
end;
|
|
|
|
Result := s;
|
|
|
|
s := '';
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function GRLW(var s: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
l: Longint;
|
|
|
|
begin
|
|
|
|
l := Length(s);
|
|
|
|
while l >= 1 do
|
|
|
|
begin
|
|
|
|
if s[l] = ' ' then
|
|
|
|
begin
|
|
|
|
Result := copy(s, l+1, MaxInt);
|
|
|
|
Delete(s, l, MaxInt);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
Dec(l);
|
|
|
|
end;
|
|
|
|
Result := s;
|
|
|
|
s := '';
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function StrToFloat(const s: TbtString): Extended;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
i: longint;
|
|
|
|
begin
|
2008-08-01 13:23:09 +02:00
|
|
|
Val(string(s), Result, i);
|
2006-08-18 10:34:39 +02:00
|
|
|
if i <> 0 then raise Exception.Create(RPS_InvalidFloat);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function IntToStr(I: LongInt): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
2008-08-01 13:23:09 +02:00
|
|
|
s: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Str(i, s);
|
|
|
|
IntToStr := s;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function FloatToStr(E: Extended): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
2008-08-01 13:23:09 +02:00
|
|
|
s: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Str(e:0:12, s);
|
|
|
|
result := s;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function StrToInt(const S: TbtString): LongInt;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
e: Integer;
|
|
|
|
Res: LongInt;
|
|
|
|
begin
|
2008-08-01 13:23:09 +02:00
|
|
|
Val(string(S), Res, e);
|
2006-05-30 16:23:25 +02:00
|
|
|
if e <> 0 then
|
|
|
|
StrToInt := -1
|
|
|
|
else
|
|
|
|
StrToInt := Res;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function StrToIntDef(const S: TbtString; Def: LongInt): LongInt;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
e: Integer;
|
|
|
|
Res: LongInt;
|
|
|
|
begin
|
2008-08-01 13:23:09 +02:00
|
|
|
Val(string(S), Res, e);
|
2006-05-30 16:23:25 +02:00
|
|
|
if e <> 0 then
|
|
|
|
StrToIntDef := Def
|
|
|
|
else
|
|
|
|
StrToIntDef := Res;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
constructor TPSList.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
FCount := 0;
|
|
|
|
FCapacity := 16;
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
|
|
|
FCheckCount := 0;
|
|
|
|
{$ENDIF}
|
|
|
|
GetMem(FData, 64);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function MM(i1,i2: Integer): Integer;
|
|
|
|
begin
|
|
|
|
if ((i1 div i2) * i2) < i1 then
|
|
|
|
mm := (i1 div i2 + 1) * i2
|
|
|
|
else
|
|
|
|
mm := (i1 div i2) * i2;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
|
|
|
procedure TPSList.Recreate;
|
|
|
|
var
|
|
|
|
NewData: PPointerList;
|
|
|
|
NewCapacity: Cardinal;
|
|
|
|
I: Longint;
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
FCheckCount := 0;
|
|
|
|
NewCapacity := mm(FCount, FCapacityInc);
|
|
|
|
if NewCapacity < 64 then NewCapacity := 64;
|
|
|
|
GetMem(NewData, NewCapacity * 4);
|
|
|
|
for I := 0 to Longint(FCount) -1 do
|
|
|
|
begin
|
|
|
|
NewData^[i] := FData^[I];
|
|
|
|
end;
|
|
|
|
FreeMem(FData, FCapacity * 4);
|
|
|
|
FData := NewData;
|
|
|
|
FCapacity := NewCapacity;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
function TPSList.Add(P: Pointer): Longint;
|
|
|
|
begin
|
|
|
|
if FCount >= FCapacity then
|
|
|
|
begin
|
|
|
|
Inc(FCapacity, FCapacityInc);// := FCount + 1;
|
|
|
|
ReAllocMem(FData, FCapacity shl 2);
|
|
|
|
end;
|
|
|
|
FData[FCount] := P; // Instead of SetItem
|
|
|
|
Result := FCount;
|
|
|
|
Inc(FCount);
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
|
|
|
Inc(FCheckCount);
|
|
|
|
if FCheckCount > FMaxCheckCount then Recreate;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSList.AddBlock(List: PPointerList; Count: Longint);
|
|
|
|
var
|
|
|
|
L: Longint;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Longint(FCount) + Count > Longint(FCapacity) then
|
|
|
|
begin
|
|
|
|
Inc(FCapacity, mm(Count, FCapacityInc));
|
|
|
|
ReAllocMem(FData, FCapacity shl 2);
|
|
|
|
end;
|
|
|
|
for L := 0 to Count -1 do
|
|
|
|
begin
|
|
|
|
FData^[FCount] := List^[L];
|
|
|
|
Inc(FCount);
|
|
|
|
end;
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
|
|
|
Inc(FCheckCount);
|
|
|
|
if FCheckCount > FMaxCheckCount then Recreate;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure TPSList.DeleteLast;
|
|
|
|
begin
|
|
|
|
if FCount = 0 then Exit;
|
|
|
|
Dec(FCount);
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
|
|
|
Inc(FCheckCount);
|
|
|
|
if FCheckCount > FMaxCheckCount then Recreate;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure TPSList.Delete(Nr: Cardinal);
|
|
|
|
begin
|
|
|
|
if FCount = 0 then Exit;
|
|
|
|
if Nr < FCount then
|
|
|
|
begin
|
|
|
|
Move(FData[Nr + 1], FData[Nr], (FCount - Nr) * 4);
|
|
|
|
Dec(FCount);
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
|
|
|
Inc(FCheckCount);
|
|
|
|
if FCheckCount > FMaxCheckCount then Recreate;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure TPSList.Remove(P: Pointer);
|
|
|
|
var
|
|
|
|
I: Cardinal;
|
|
|
|
begin
|
|
|
|
if FCount = 0 then Exit;
|
|
|
|
I := 0;
|
|
|
|
while I < FCount do
|
|
|
|
begin
|
|
|
|
if FData[I] = P then
|
|
|
|
begin
|
|
|
|
Delete(I);
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
Inc(I);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure TPSList.Clear;
|
|
|
|
begin
|
|
|
|
FCount := 0;
|
|
|
|
{$IFNDEF PS_NOSMARTLIST}
|
|
|
|
Recreate;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
destructor TPSList.Destroy;
|
|
|
|
begin
|
|
|
|
FreeMem(FData, FCapacity * 4);
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure TPSList.SetItem(Nr: Cardinal; P: Pointer);
|
|
|
|
begin
|
|
|
|
if (FCount = 0) or (Nr >= FCount) then
|
|
|
|
Exit;
|
|
|
|
FData[Nr] := P;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
function TPSList.GetItem(Nr: Cardinal): Pointer; {12}
|
|
|
|
begin
|
|
|
|
if Nr < FCount then
|
|
|
|
GetItem := FData[Nr]
|
|
|
|
else
|
|
|
|
GetItem := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
function TPSStringList.Count: LongInt;
|
|
|
|
begin
|
|
|
|
count := List.count;
|
|
|
|
end;
|
2008-08-01 13:23:09 +02:00
|
|
|
type pStr = ^TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSStringList.GetItem(Nr: LongInt): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
S: PStr;
|
|
|
|
begin
|
|
|
|
s := List.GetItem(Nr);
|
|
|
|
if s = nil then
|
|
|
|
Result := ''
|
|
|
|
else
|
|
|
|
|
|
|
|
Result := s^;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSStringList.SetItem(Nr: LongInt; const s: TbtString);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
p: PStr;
|
|
|
|
begin
|
|
|
|
p := List.GetItem(Nr);
|
|
|
|
if p = nil
|
|
|
|
then
|
|
|
|
Exit;
|
|
|
|
p^ := s;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSStringList.Add(const P: TbtString);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
w: PStr;
|
|
|
|
begin
|
|
|
|
new(w);
|
|
|
|
w^ := p;
|
|
|
|
List.Add(w);
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure TPSStringList.Delete(NR: LongInt);
|
|
|
|
var
|
|
|
|
W: PStr;
|
|
|
|
begin
|
|
|
|
W := list.getitem(nr);
|
|
|
|
if w<>nil then
|
|
|
|
begin
|
|
|
|
dispose(w);
|
|
|
|
end;
|
|
|
|
list.Delete(Nr);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSStringList.Clear;
|
|
|
|
begin
|
|
|
|
while List.Count > 0 do Delete(0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TPSStringList.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
List := TPSList.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TPSStringList.Destroy;
|
|
|
|
begin
|
|
|
|
while List.Count > 0 do
|
|
|
|
Delete(0);
|
|
|
|
List.Destroy;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function Fw(const S: TbtString): TbtString; // First word
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
x: integer;
|
|
|
|
begin
|
2008-08-01 13:23:09 +02:00
|
|
|
x := pos(tbtstring(' '), s);
|
2006-05-30 16:23:25 +02:00
|
|
|
if x > 0
|
|
|
|
then Fw := Copy(S, 1, x - 1)
|
|
|
|
else Fw := S;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
2008-08-01 13:23:09 +02:00
|
|
|
function FastUpperCase(const s: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
{Fast uppercase}
|
|
|
|
var
|
|
|
|
I: Integer;
|
2008-08-01 13:23:09 +02:00
|
|
|
C: tbtChar;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := S;
|
|
|
|
I := Length(Result);
|
|
|
|
while I > 0 do
|
|
|
|
begin
|
|
|
|
C := Result[I];
|
|
|
|
if c in [#97..#122] then
|
2008-08-01 13:23:09 +02:00
|
|
|
Result[I] := tbtchar(Ord(Result[I]) -32);
|
2006-05-30 16:23:25 +02:00
|
|
|
Dec(I);
|
|
|
|
end;
|
|
|
|
end;
|
2008-08-01 13:23:09 +02:00
|
|
|
function FastLowerCase(const s: TbtString): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
{Fast lowercase}
|
|
|
|
var
|
|
|
|
I: Integer;
|
2008-08-01 13:23:09 +02:00
|
|
|
C: tbtChar;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := S;
|
|
|
|
I := Length(Result);
|
|
|
|
while I > 0 do
|
|
|
|
begin
|
|
|
|
C := Result[I];
|
|
|
|
if C in [#65..#90] then
|
2008-08-01 13:23:09 +02:00
|
|
|
Result[I] := tbtchar(Ord(Result[I]) + 32);
|
2006-05-30 16:23:25 +02:00
|
|
|
Dec(I);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
type
|
|
|
|
TRTab = record
|
2008-08-01 13:23:09 +02:00
|
|
|
name: TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
c: TPSPasToken;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
2006-08-18 10:34:39 +02:00
|
|
|
KEYWORD_COUNT = 65; //*NVDS
|
2006-05-30 16:23:25 +02:00
|
|
|
LookupTable: array[0..KEYWORD_COUNT - 1] of TRTab = (
|
|
|
|
(name: 'AND'; c: CSTII_and),
|
|
|
|
(name: 'ARRAY'; c: CSTII_array),
|
|
|
|
(name: 'AS'; c: CSTII_as),
|
|
|
|
(name: 'BEGIN'; c: CSTII_begin),
|
|
|
|
(name: 'CASE'; c: CSTII_case),
|
|
|
|
(name: 'CHR'; c: CSTII_chr),
|
|
|
|
(name: 'CLASS'; c: CSTII_class),
|
|
|
|
(name: 'CONST'; c: CSTII_const),
|
|
|
|
(name: 'CONSTRUCTOR'; c: CSTII_constructor),
|
|
|
|
(name: 'DESTRUCTOR'; c: CSTII_destructor),
|
|
|
|
(name: 'DIV'; c: CSTII_div),
|
|
|
|
(name: 'DO'; c: CSTII_do),
|
|
|
|
(name: 'DOWNTO'; c: CSTII_downto),
|
|
|
|
(name: 'ELSE'; c: CSTII_else),
|
|
|
|
(name: 'END'; c: CSTII_end),
|
|
|
|
(name: 'EXCEPT'; c: CSTII_except),
|
|
|
|
(name: 'EXIT'; c: CSTII_exit),
|
|
|
|
(name: 'EXPORT'; c: CSTII_Export),
|
|
|
|
(name: 'EXTERNAL'; c: CSTII_External),
|
2006-08-18 10:34:39 +02:00
|
|
|
(Name: 'FINALIZATION'; c : CSTII_finalization),//* Nvds
|
2006-05-30 16:23:25 +02:00
|
|
|
(name: 'FINALLY'; c: CSTII_finally),
|
|
|
|
(name: 'FOR'; c: CSTII_for),
|
|
|
|
(name: 'FORWARD'; c: CSTII_Forward),
|
|
|
|
(name: 'FUNCTION'; c: CSTII_function),
|
|
|
|
(name: 'GOTO'; c: CSTII_Goto),
|
|
|
|
(name: 'IF'; c: CSTII_if),
|
|
|
|
(name: 'IMPLEMENTATION'; c: CSTII_Implementation),
|
|
|
|
(name: 'IN'; c: CSTII_in),
|
|
|
|
(name: 'INHERITED'; c: CSTII_inherited),
|
2006-08-18 10:34:39 +02:00
|
|
|
(Name: 'INITIALIZATION'; c: CSTII_initialization), //* Nvds
|
2006-05-30 16:23:25 +02:00
|
|
|
(name: 'INTERFACE'; c: CSTII_Interface),
|
|
|
|
(name: 'IS'; c: CSTII_is),
|
|
|
|
(name: 'LABEL'; c: CSTII_Label),
|
|
|
|
(name: 'MOD'; c: CSTII_mod),
|
|
|
|
(name: 'NIL'; c: CSTII_nil),
|
|
|
|
(name: 'NOT'; c: CSTII_not),
|
|
|
|
(name: 'OF'; c: CSTII_of),
|
|
|
|
(name: 'OR'; c: CSTII_or),
|
|
|
|
(name: 'ORD'; c: CSTII_ord),
|
|
|
|
(name: 'OUT'; c: CSTII_Out),
|
|
|
|
(name: 'OVERRIDE'; c: CSTII_override),
|
|
|
|
//(name: 'DEFAULT'; c: CSTII_default), //Birb (if added, don't forget to increase KEYWORD_COUNT)
|
|
|
|
(name: 'PRIVATE'; c: CSTII_private),
|
|
|
|
(name: 'PROCEDURE'; c: CSTII_procedure),
|
|
|
|
(name: 'PROGRAM'; c: CSTII_program),
|
|
|
|
(name: 'PROPERTY'; c: CSTII_property),
|
|
|
|
(name: 'PROTECTED'; c: CSTII_protected),
|
|
|
|
(name: 'PUBLIC'; c: CSTII_public),
|
|
|
|
(name: 'PUBLISHED'; c: CSTII_published),
|
|
|
|
(name: 'RECORD'; c: CSTII_record),
|
|
|
|
(name: 'REPEAT'; c: CSTII_repeat),
|
|
|
|
(name: 'SET'; c: CSTII_set),
|
|
|
|
(name: 'SHL'; c: CSTII_shl),
|
|
|
|
(name: 'SHR'; c: CSTII_shr),
|
|
|
|
(name: 'THEN'; c: CSTII_then),
|
|
|
|
(name: 'TO'; c: CSTII_to),
|
|
|
|
(name: 'TRY'; c: CSTII_try),
|
|
|
|
(name: 'TYPE'; c: CSTII_type),
|
|
|
|
(name: 'UNIT'; c: CSTII_Unit),
|
|
|
|
(name: 'UNTIL'; c: CSTII_until),
|
|
|
|
(name: 'USES'; c: CSTII_uses),
|
|
|
|
(name: 'VAR'; c: CSTII_var),
|
|
|
|
(name: 'VIRTUAL'; c: CSTII_virtual),
|
|
|
|
(name: 'WHILE'; c: CSTII_while),
|
|
|
|
(name: 'WITH'; c: CSTII_with),
|
|
|
|
(name: 'XOR'; c: CSTII_xor));
|
|
|
|
|
|
|
|
function TPSPascalParser.GetCol: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := FRealPosition - FLastEnterPos + 1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSPascalParser.Next;
|
|
|
|
var
|
|
|
|
Err: TPSParserErrorKind;
|
2008-08-01 13:23:09 +02:00
|
|
|
FLastUpToken: TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
function CheckReserved(Const S: ShortString; var CurrTokenId: TPSPasToken): Boolean;
|
|
|
|
var
|
|
|
|
L, H, I: LongInt;
|
2008-08-01 13:23:09 +02:00
|
|
|
J: tbtChar;
|
2006-05-30 16:23:25 +02:00
|
|
|
SName: ShortString;
|
|
|
|
begin
|
|
|
|
L := 0;
|
|
|
|
J := S[0];
|
|
|
|
H := KEYWORD_COUNT-1;
|
|
|
|
while L <= H do
|
|
|
|
begin
|
|
|
|
I := (L + H) shr 1;
|
|
|
|
SName := LookupTable[i].Name;
|
|
|
|
if J = SName[0] then
|
|
|
|
begin
|
|
|
|
if S = SName then
|
|
|
|
begin
|
|
|
|
CheckReserved := True;
|
|
|
|
CurrTokenId := LookupTable[I].c;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
if S > SName then
|
|
|
|
L := I + 1
|
|
|
|
else
|
|
|
|
H := I - 1;
|
|
|
|
end else
|
|
|
|
if S > SName then
|
|
|
|
L := I + 1
|
|
|
|
else
|
|
|
|
H := I - 1;
|
|
|
|
end;
|
|
|
|
CheckReserved := False;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function _GetToken(CurrTokenPos, CurrTokenLen: Cardinal): TbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
2008-08-01 13:23:09 +02:00
|
|
|
s: tbtString;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
SetLength(s, CurrTokenLen);
|
|
|
|
Move(FText[CurrTokenPos], S[1], CurrtokenLen);
|
2007-03-16 10:59:59 +01:00
|
|
|
Result := s;
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function ParseToken(var CurrTokenPos, CurrTokenLen: Cardinal; var CurrTokenId: TPSPasToken): TPSParserErrorKind;
|
|
|
|
{Parse the token}
|
|
|
|
var
|
|
|
|
ct, ci: Cardinal;
|
|
|
|
hs: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
p: {$IFDEF DELPHI4UP}PAnsiChar{$ELSE}PChar{$ENDIF};
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
ParseToken := iNoError;
|
|
|
|
ct := CurrTokenPos;
|
|
|
|
case FText[ct] of
|
|
|
|
#0:
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_EOF;
|
|
|
|
CurrTokenLen := 0;
|
|
|
|
end;
|
|
|
|
'A'..'Z', 'a'..'z', '_':
|
|
|
|
begin
|
|
|
|
ci := ct + 1;
|
|
|
|
while (FText[ci] in ['_', '0'..'9', 'a'..'z', 'A'..'Z']) do begin
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
|
2007-03-16 10:59:59 +01:00
|
|
|
FLastUpToken := _GetToken(CurrTokenPos, CurrtokenLen);
|
2008-08-01 13:23:09 +02:00
|
|
|
p := {$IFDEF DELPHI4UP}PAnsiChar{$ELSE}pchar{$ENDIF}(FLastUpToken);
|
2006-05-30 16:23:25 +02:00
|
|
|
while p^<>#0 do
|
|
|
|
begin
|
|
|
|
if p^ in [#97..#122] then
|
|
|
|
Dec(Byte(p^), 32);
|
|
|
|
inc(p);
|
|
|
|
end;
|
|
|
|
if not CheckReserved(FLastUpToken, CurrTokenId) then
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Identifier;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
'$':
|
|
|
|
begin
|
|
|
|
ci := ct + 1;
|
|
|
|
|
|
|
|
while (FText[ci] in ['0'..'9', 'a'..'f', 'A'..'F'])
|
|
|
|
do Inc(ci);
|
|
|
|
|
|
|
|
CurrTokenId := CSTI_HexInt;
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
end;
|
|
|
|
|
|
|
|
'0'..'9':
|
|
|
|
begin
|
|
|
|
hs := False;
|
|
|
|
ci := ct;
|
|
|
|
while (FText[ci] in ['0'..'9']) do
|
|
|
|
begin
|
|
|
|
Inc(ci);
|
|
|
|
if (FText[ci] = '.') and (not hs) then
|
|
|
|
begin
|
|
|
|
if FText[ci+1] = '.' then break;
|
|
|
|
hs := True;
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
end;
|
2007-03-16 10:59:59 +01:00
|
|
|
if (FText[ci] in ['E','e']) and ((FText[ci+1] in ['0'..'9'])
|
|
|
|
or ((FText[ci+1] in ['+','-']) and (FText[ci+2] in ['0'..'9']))) then
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
hs := True;
|
2006-08-18 10:34:39 +02:00
|
|
|
Inc(ci);
|
|
|
|
if FText[ci] in ['+','-'] then
|
|
|
|
Inc(ci);
|
|
|
|
repeat
|
|
|
|
Inc(ci);
|
|
|
|
until not (FText[ci] in ['0'..'9']);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
if hs
|
|
|
|
then CurrTokenId := CSTI_Real
|
|
|
|
else CurrTokenId := CSTI_Integer;
|
|
|
|
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
#39:
|
|
|
|
begin
|
|
|
|
ci := ct + 1;
|
|
|
|
while true do
|
|
|
|
begin
|
|
|
|
if (FText[ci] = #0) or (FText[ci] = #13) or (FText[ci] = #10) then Break;
|
|
|
|
if (FText[ci] = #39) then
|
|
|
|
begin
|
|
|
|
if FText[ci+1] = #39 then
|
|
|
|
Inc(ci)
|
|
|
|
else
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
if FText[ci] = #39 then
|
|
|
|
CurrTokenId := CSTI_String
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_String;
|
|
|
|
ParseToken := iStringError;
|
|
|
|
end;
|
|
|
|
CurrTokenLen := ci - ct + 1;
|
|
|
|
end;
|
|
|
|
'#':
|
|
|
|
begin
|
|
|
|
ci := ct + 1;
|
|
|
|
if FText[ci] = '$' then
|
|
|
|
begin
|
|
|
|
inc(ci);
|
|
|
|
while (FText[ci] in ['A'..'F', 'a'..'f', '0'..'9']) do begin
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
CurrTokenId := CSTI_Char;
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
while (FText[ci] in ['0'..'9']) do begin
|
|
|
|
Inc(ci);
|
2007-03-16 10:59:59 +01:00
|
|
|
end;
|
2006-05-30 16:23:25 +02:00
|
|
|
if FText[ci] in ['A'..'Z', 'a'..'z', '_'] then
|
|
|
|
begin
|
|
|
|
ParseToken := iCharError;
|
|
|
|
CurrTokenId := CSTI_Char;
|
|
|
|
end else
|
|
|
|
CurrTokenId := CSTI_Char;
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
'=':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Equal;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
'>':
|
|
|
|
begin
|
|
|
|
if FText[ct + 1] = '=' then
|
|
|
|
begin
|
|
|
|
CurrTokenid := CSTI_GreaterEqual;
|
|
|
|
CurrTokenLen := 2;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrTokenid := CSTI_Greater;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
'<':
|
|
|
|
begin
|
|
|
|
if FText[ct + 1] = '=' then
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_LessEqual;
|
|
|
|
CurrTokenLen := 2;
|
|
|
|
end else
|
|
|
|
if FText[ct + 1] = '>' then
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_NotEqual;
|
|
|
|
CurrTokenLen := 2;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Less;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
')':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_CloseRound;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
'(':
|
|
|
|
begin
|
|
|
|
if FText[ct + 1] = '*' then
|
|
|
|
begin
|
|
|
|
ci := ct + 1;
|
|
|
|
while (FText[ci] <> #0) do begin
|
|
|
|
if (FText[ci] = '*') and (FText[ci + 1] = ')') then
|
|
|
|
Break;
|
|
|
|
if FText[ci] = #13 then
|
|
|
|
begin
|
|
|
|
inc(FRow);
|
|
|
|
if FText[ci+1] = #10 then
|
|
|
|
inc(ci);
|
|
|
|
FLastEnterPos := ci +1;
|
|
|
|
end else if FText[ci] = #10 then
|
|
|
|
begin
|
|
|
|
inc(FRow);
|
|
|
|
FLastEnterPos := ci +1;
|
|
|
|
end;
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
if (FText[ci] = #0) then
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTIINT_Comment;
|
|
|
|
ParseToken := iCommentError;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTIINT_Comment;
|
|
|
|
Inc(ci, 2);
|
|
|
|
end;
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_OpenRound;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
'[':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_OpenBlock;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
']':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_CloseBlock;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
',':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Comma;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
'.':
|
|
|
|
begin
|
|
|
|
if FText[ct + 1] = '.' then
|
|
|
|
begin
|
|
|
|
CurrTokenLen := 2;
|
|
|
|
CurrTokenId := CSTI_TwoDots;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Period;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
'@':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_AddressOf;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
'^':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Dereference;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
';':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Semicolon;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
':':
|
|
|
|
begin
|
|
|
|
if FText[ct + 1] = '=' then
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Assignment;
|
|
|
|
CurrTokenLen := 2;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Colon;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
'+':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Plus;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
'-':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Minus;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
'*':
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Multiply;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
'/':
|
|
|
|
begin
|
|
|
|
if FText[ct + 1] = '/' then
|
|
|
|
begin
|
|
|
|
ci := ct + 1;
|
|
|
|
while (FText[ci] <> #0) and (FText[ci] <> #13) and
|
|
|
|
(FText[ci] <> #10) do begin
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
if (FText[ci] = #0) then
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTIINT_Comment;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTIINT_Comment;
|
|
|
|
end;
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTI_Divide;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
#32, #9, #13, #10:
|
|
|
|
begin
|
|
|
|
ci := ct;
|
|
|
|
while (FText[ci] in [#32, #9, #13, #10]) do
|
|
|
|
begin
|
|
|
|
if FText[ci] = #13 then
|
|
|
|
begin
|
|
|
|
inc(FRow);
|
|
|
|
if FText[ci+1] = #10 then
|
|
|
|
inc(ci);
|
|
|
|
FLastEnterPos := ci +1;
|
|
|
|
end else if FText[ci] = #10 then
|
|
|
|
begin
|
|
|
|
inc(FRow);
|
|
|
|
FLastEnterPos := ci +1;
|
|
|
|
end;
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
CurrTokenId := CSTIINT_WhiteSpace;
|
|
|
|
CurrTokenLen := ci - ct;
|
|
|
|
end;
|
|
|
|
'{':
|
|
|
|
begin
|
|
|
|
ci := ct + 1;
|
|
|
|
while (FText[ci] <> #0) and (FText[ci] <> '}') do begin
|
|
|
|
if FText[ci] = #13 then
|
|
|
|
begin
|
|
|
|
inc(FRow);
|
|
|
|
if FText[ci+1] = #10 then
|
|
|
|
inc(ci);
|
|
|
|
FLastEnterPos := ci + 1;
|
|
|
|
end else if FText[ci] = #10 then
|
|
|
|
begin
|
|
|
|
inc(FRow);
|
|
|
|
FLastEnterPos := ci + 1;
|
|
|
|
end;
|
|
|
|
Inc(ci);
|
|
|
|
end;
|
|
|
|
if (FText[ci] = #0) then
|
|
|
|
begin
|
|
|
|
CurrTokenId := CSTIINT_Comment;
|
|
|
|
ParseToken := iCommentError;
|
|
|
|
end else
|
|
|
|
CurrTokenId := CSTIINT_Comment;
|
|
|
|
CurrTokenLen := ci - ct + 1;
|
|
|
|
end;
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
ParseToken := iSyntaxError;
|
|
|
|
CurrTokenId := CSTIINT_Comment;
|
|
|
|
CurrTokenLen := 1;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
begin
|
|
|
|
if FText = nil then
|
|
|
|
begin
|
|
|
|
FTokenLength := 0;
|
|
|
|
FRealPosition := 0;
|
|
|
|
FTokenId := CSTI_EOF;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
repeat
|
|
|
|
FRealPosition := FRealPosition + FTokenLength;
|
|
|
|
Err := ParseToken(FRealPosition, FTokenLength, FTokenID);
|
|
|
|
if Err <> iNoError then
|
|
|
|
begin
|
|
|
|
FTokenLength := 0;
|
|
|
|
FTokenId := CSTI_EOF;
|
|
|
|
FToken := '';
|
|
|
|
FOriginalToken := '';
|
|
|
|
if @FParserError <> nil then FParserError(Self, Err);
|
|
|
|
exit;
|
|
|
|
end;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
case FTokenID of
|
|
|
|
CSTIINT_Comment: if not FEnableComments then Continue else
|
|
|
|
begin
|
|
|
|
SetLength(FOriginalToken, FTokenLength);
|
|
|
|
Move(FText[CurrTokenPos], FOriginalToken[1], FTokenLength);
|
|
|
|
FToken := FOriginalToken;
|
|
|
|
end;
|
|
|
|
CSTIINT_WhiteSpace: if not FEnableWhitespaces then Continue else
|
|
|
|
begin
|
|
|
|
SetLength(FOriginalToken, FTokenLength);
|
|
|
|
Move(FText[CurrTokenPos], FOriginalToken[1], FTokenLength);
|
|
|
|
FToken := FOriginalToken;
|
|
|
|
end;
|
|
|
|
CSTI_Integer, CSTI_Real, CSTI_String, CSTI_Char, CSTI_HexInt:
|
|
|
|
begin
|
|
|
|
SetLength(FOriginalToken, FTokenLength);
|
|
|
|
Move(FText[CurrTokenPos], FOriginalToken[1], FTokenLength);
|
|
|
|
FToken := FOriginalToken;
|
|
|
|
end;
|
|
|
|
CSTI_Identifier:
|
|
|
|
begin
|
|
|
|
SetLength(FOriginalToken, FTokenLength);
|
|
|
|
Move(FText[CurrTokenPos], FOriginalToken[1], FTokenLength);
|
|
|
|
FToken := FLastUpToken;
|
|
|
|
end;
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
FOriginalToken := '';
|
|
|
|
FToken := '';
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Break;
|
|
|
|
until False;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSPascalParser.SetText(const Data: TbtString);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
FData := Data;
|
|
|
|
FText := Pointer(FData);
|
|
|
|
FTokenLength := 0;
|
|
|
|
FRealPosition := 0;
|
|
|
|
FTokenId := CSTI_EOF;
|
|
|
|
FLastEnterPos := 0;
|
|
|
|
FRow := 1;
|
|
|
|
Next;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSList.IndexOf(P: Pointer): Longint;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
for i := FCount -1 downto 0 do
|
|
|
|
begin
|
|
|
|
if FData[i] = p then
|
|
|
|
begin
|
|
|
|
result := i;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
result := -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|
|
|