大★★大大大大大★大大大大大★大★大大大大大大★★大 PARser大★大大大★★大大★大大★★大大★★★大★★大大大★★} constructor pARser. Create eaIn inherited creat HIstory :=TStringList Create Style des tructor TIParser Destroyi n HIstory. Free inherited Destroy function TIParser To ken: stringi Stskip=['',#10,#13]; I SENDIF RA DE [SIFDEF RA B] Stskip #10#13 I SENDIF RA B] edure Skil P[0] of if EStyle psPascal then F if F nil then IParserError(ieBadRemark, P Fpc Progr am) F+1 f Styl psPascal then IParserError(ie BadRemar k Epc Program)i if (EStyle ps Pascal) and (P[l]=l*)then
{*************************** TIParser ****************************} constructor TIParser.Create; begin inherited Create; FHistory := TStringList.Create; HistorySize := 10; Style := psPascal; end; destructor TIParser.Destroy; begin FHistory.Free; inherited Destroy; end; function TIParser.Token: string; var P, F: PChar; const {$IFDEF RA_D} StSkip = [' ', #10, #13]; {$ENDIF RA_D} {$IFDEF RA_B} StSkip = ' '#10#13; {$ENDIF RA_B} procedure SkipComments; begin case P[0] of '{': if FStyle = psPascal then begin F := StrScan(P + 1, '}'); if F = nil then IParserError(ieBadRemark, P - FpcProgram); P := F + 1; end; '}': if FStyle = psPascal then IParserError(ieBadRemark, P - FpcProgram); '(': if (FStyle = psPascal) and (P[1] = '*') then begin F := P + 2;
hile true do F : Strscan(F if F= nil then IParserError (ieBadRemark, P Fpc Program ifF[1]=') inc(F)i break end: inc(F) end if STyle psPascal then begin f(P[1] )')then IParserError(ieBadRemar k, P Epc Prog end else if EStyle =psCpp then if (P[l] /1) then IParserError(ieBadRemark p if (EStyle in [psPascal, psCpp]) and (P[1]='/')then eg F Str Scan(P 1,#13) if f= nil then F StrEnd(P 1)i else if (EStyle ps Cpp) and (P[l] ='*')then begin while true do beg StrScan(F,i*') if F= nil then IParserError (ieBadRemark, P -Epc Progr am) if F[l1 inc(F) inc(F)
while true do begin F := StrScan(F, '*'); if F = nil then IParserError(ieBadRemark, P - FpcProgram); if F[1] = ')' then begin inc(F); break; end; inc(F); end; P := F + 1; end; '*': if FStyle = psPascal then begin if (P[1] = ')') then IParserError(ieBadRemark, P - FpcProgram) end else if FStyle = psCpp then if (P[1] = '/') then IParserError(ieBadRemark, P - FpcProgram); '/': if (FStyle in [psPascal, psCpp]) and (P[1] = '/') then begin F := StrScan(P + 1, #13); if F = nil then F := StrEnd(P + 1); P := F; end else if (FStyle = psCpp) and (P[1] = '*') then begin F := P + 2; while true do begin F := StrScan(F, '*'); if F = nil then IParserError(ieBadRemark, P - FpcProgram); if F[1] = '/' then begin inc(F); break; end; inc(F); end; P := F + 1;
if (EStyle in [psPython, psPerl])[ ar reProgram) F:= StrScan(P +1,#13 if F= nil then F:= StrEnd(P 1) if EStyle psv then begin F:= StrScan(P 1, #13) if F= nil then F: StrEnd(P 1)
end; '#': if (FStyle in [psPython, psPerl]) { and ((P = FpcProgram) or (P[-1] in [#10, #13])) } then begin F := StrScan(P + 1, #13); if F = nil then F := StrEnd(P + 1); P := F; end; '''': if FStyle = psVB then begin F := StrScan(P + 1, #13); if F = nil then F := StrEnd(P + 1); P := F; end; end; end;