Ignore:
Timestamp:
Aug 10, 2010, 1:48:38 PM (14 years ago)
Author:
george
Message:

Fix: View proper source file after click to error message.
Made partial changes to support unit interface and implementation sections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/Analyze/UParser.pas

    r54 r55  
    5151    procedure ParseExpression(SourceCode: TExpression);
    5252    procedure ParseUsedModuleList(SourceCode: TUsedModuleList);
    53     procedure ParseModule(SourceCode: TModule);
    54     procedure ParseUnit(SourceCode: TModule);
    55     procedure ParseProgram(SourceCode: TModule);
     53    function ParseModule: TModule;
     54    procedure ParseUnit(SourceCode: TModuleUnit);
     55    procedure ParseUnitInterface(SourceCode: TUnitInterface);
     56    procedure ParseUnitImplementation(SourceCode: TUnitImplementation);
     57    procedure ParseProgram(SourceCode: TModuleProgram);
    5658    procedure ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: char = ';');
    5759    function ParseCommand(SourceCode: TCommonBlock): TCommand;
     
    628630{ TParserModule }
    629631
    630 procedure TPascalParser.ParseModule(SourceCode: TModule);
    631 begin
    632   if FNextToken = 'program' then
    633     ParseProgram(SourceCode)
    634   else if FNextToken = 'unit' then
    635     ParseUnit(SourceCode)
    636   else
    637     ParseProgram(SourceCode);
    638 end;
    639 
    640 procedure TPascalParser.ParseProgram(SourceCode: TModule);
     632function TPascalParser.ParseModule: TModule;
     633begin
     634  if FNextToken = 'unit' then begin
     635    Result := TModuleUnit.Create;
     636    ParseUnit(TModuleUnit(Result));
     637  end else begin //if FNextToken = 'program' then begin
     638    Result := TModuleProgram.Create;
     639    ParseProgram(TModuleProgram(Result));
     640  end;
     641end;
     642
     643procedure TPascalParser.ParseProgram(SourceCode: TModuleProgram);
    641644var
    642645  Identifier: string;
    643646begin
    644   with SourceCode do
    645   begin
    646     if FNextToken = 'program' then
    647     begin
     647  with SourceCode do begin
     648    if FNextToken = 'program' then begin
    648649      Expect('program');
    649650      Name := ReadCode;
    650       ModuleType := mdProgram;
    651651      Expect(';');
    652652    end else Name := '';
     
    656656      ParseUsedModuleList(UsedModules);
    657657
    658     ParseCommonBlock(SourceCode, '.');
    659   end;
    660 end;
    661 
    662 procedure TPascalParser.ParseUnit(SourceCode: TModule);
     658    ParseCommonBlock(Body, '.');
     659  end;
     660end;
     661
     662procedure TPascalParser.ParseUnit(SourceCode: TModuleUnit);
    663663var
    664664  NewModule: TModule;
    665665begin
    666666  Expect('unit');
    667   with Sourcecode do
    668   begin
     667  with Sourcecode do begin
    669668    Name := ReadCode;
    670     ModuleType := mdUnit;
    671669  end;
    672670  Expect(';');
    673   //ParseInterface;
    674   //ParseImplementation;
    675 end;
    676 
    677 { TParserProgram }
     671
     672  ParseUnitInterface(SourceCode.InterfaceSection);
     673  if FNextToken = 'implementation' then
     674    ParseUnitImplementation(SourceCode.ImplementationSection);
     675end;
     676
     677procedure TPascalParser.ParseUnitInterface(SourceCode: TUnitInterface);
     678begin
     679  Expect('interface');
     680  // Uses section
     681  if FNextToken = 'uses' then
     682    ParseUsedModuleList(SourceCode.UsedModules);
     683
     684  ParseCommonBlock(SourceCode.Body, '.');
     685end;
     686
     687procedure TPascalParser.ParseUnitImplementation(SourceCode: TUnitImplementation);
     688begin
     689  Expect('implementation');
     690
     691  // Uses section
     692  if FNextToken = 'uses' then
     693    ParseUsedModuleList(SourceCode.UsedModules);
     694
     695  ParseCommonBlock(SourceCode.Body, '.');
     696end;
    678697
    679698{ TParserCommonBlock }
Note: See TracChangeset for help on using the changeset viewer.