1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
{ ---------------------------------------------------------------------
This is a simple program to check whether fcl-passrc
---------------------------------------------------------------------}
program parsepp;
{$mode objfpc}{$H+}
uses SysUtils, Classes, PParser, PasTree;
type
{ We have to override abstract TPasTreeContainer methods.
See utils/fpdoc/dglobals.pp for an implementation of TFPDocEngine,
a "real" engine. }
TSimpleEngine = class(TPasTreeContainer)
public
function CreateElement(AClass: TPTreeElement; const AName: String;
AParent: TPasElement; AVisibility: TPasMemberVisibility;
const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
override;
function FindElement(const AName: String): TPasElement; override;
end;
function TSimpleEngine.CreateElement(AClass: TPTreeElement; const AName: String;
AParent: TPasElement; AVisibility: TPasMemberVisibility;
const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
begin
Writeln(AName,' : ',AClass.ClassName,' at ',ASourceFilename,':',ASourceLinenumber);
Result := AClass.Create(AName, AParent);
Result.Visibility := AVisibility;
Result.SourceFilename := ASourceFilename;
Result.SourceLinenumber := ASourceLinenumber;
end;
function TSimpleEngine.FindElement(const AName: String): TPasElement;
begin
{ dummy implementation, see TFPDocEngine.FindElement for a real example }
Result := nil;
end;
Procedure Usage;
begin
Writeln('Usage : ',ExtractFileName(Paramstr(0)),' [-h|--help] options ');
Writeln('-h or --help shows this help');
Writeln('All other options are passed as-is to the parser');
Halt(0);
end;
var
M: TPasModule;
E: TPasTreeContainer;
I: Integer;
Decls: TFPList;
cmdline : String;
begin
cmdline:='';
if (ParamCount=0) or (Paramstr(1)='-h') or (Paramstr(1)='--help') then
Usage;
For I:=1 to ParamCount do
CmdLine:=CmdLine+' '+Paramstr(i);
E := TSimpleEngine.Create;
M := nil;
try
M := ParseSource(E, cmdline, 'linux', 'i386');
{ Cool, we successfully parsed the module.
Now output some info about it. }
if M.InterfaceSection <> nil then
begin
Decls := M.InterfaceSection.Declarations;
for I := 0 to Decls.Count - 1 do
Writeln('Interface item ', I, ': ' +
(TObject(Decls[I]) as TPasElement).Name);
end else
Writeln('No interface section --- this is not a unit, this is a ', M.ClassName);
if M.ImplementationSection <> nil then // may be nil in case of a simple program
begin
Decls := M.ImplementationSection.Declarations;
for I := 0 to Decls.Count - 1 do
Writeln('Implementation item ', I, ': ' +
(TObject(Decls[I]) as TPasElement).Name);
end;
finally
FreeAndNil(M);
FreeAndNil(E)
end;
end.
|