Ignore:
Timestamp:
Aug 10, 2010, 3:41:49 PM (14 years ago)
Author:
george
Message:

Slightly enhanced parsing of unit.

File:
1 edited

Legend:

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

    r55 r58  
    5757    procedure ParseProgram(SourceCode: TModuleProgram);
    5858    procedure ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: char = ';');
     59    procedure ParseCommonBlockInterface(SourceCode: TCommonBlock);
    5960    function ParseCommand(SourceCode: TCommonBlock): TCommand;
    6061    procedure ParseBeginEnd(SourceCode: TBeginEnd);
    61     procedure ParseFunctionList(SourceCode: TFunctionList);
     62    procedure ParseFunctionList(SourceCode: TFunctionList; IncludeBody: Boolean = True);
    6263    procedure ParseIfThenElse(SourceCode: TIfThenElse);
    6364    procedure ParseForToDo(SourceCode: TForToDo);
     
    682683    ParseUsedModuleList(SourceCode.UsedModules);
    683684
    684   ParseCommonBlock(SourceCode.Body, '.');
     685  ParseCommonBlockInterface(SourceCode.Body);
    685686end;
    686687
     
    725726end;
    726727
     728procedure TPascalParser.ParseCommonBlockInterface(SourceCode: TCommonBlock);
     729begin
     730  with SourceCode do begin
     731    while FNextToken <> 'implementation' do begin
     732      if FNextToken = 'var' then
     733        ParseVariableList(Variables)
     734      else if FNextToken = 'const' then
     735        ParseConstantList(Constants)
     736      else if FNextToken = 'type' then
     737        ParseTypeList(Types)
     738      else if FNextToken = 'procedure' then
     739        ParseFunctionList(Functions, False)
     740      else if FNextToken = 'function' then
     741        ParseFunctionList(Functions, False)
     742      else ErrorMessage(SUnknownIdentifier, [FNextToken]);
     743    end;
     744  end;
     745end;
     746
    727747{ TParserBeginEnd }
    728748
     
    750770{ TParserParseFunctionList }
    751771
    752 procedure TPascalParser.ParseFunctionList(SourceCode: TFunctionList);
     772procedure TPascalParser.ParseFunctionList(SourceCode: TFunctionList; IncludeBody: Boolean = True);
    753773var
    754774  Identifiers: TStringList;
     
    760780begin
    761781  Identifiers := TStringList.Create;
    762   with SourceCode do
    763   begin
    764     with TFunction(Items[Add(TFunction.Create)]) do
    765     begin
     782  with SourceCode do begin
     783    with TFunction(Items[Add(TFunction.Create)]) do begin
    766784      Parent := SourceCode.Parent;
    767785      if FNextToken = 'procedure' then
     
    834852        end;
    835853      end;
    836     end;
    837     Expect(';');
    838     ParseCommonBlock(TFunction(Last));
     854      Expect(';');
     855
     856      // Check directives
     857      if FNextToken = 'internal' then begin
     858        Expect('internal');
     859        Expect(';');
     860        System := True;
     861      end;
     862    end;
     863
     864    if IncludeBody then ParseCommonBlock(TFunction(Last));
    839865  end;
    840866  Identifiers.Destroy;
Note: See TracChangeset for help on using the changeset viewer.