⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umfparse.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
字号:
{  JADD - Just Another DelphiDoc: Documentation from Delphi Source Code

Copyright (C) 2002-2008   Gerold Veith

This file is part of JADD - Just Another DelphiDoc.

DelphiDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.

DelphiDoc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
}


unit UMFParse;

{Contains a simple page with buttons to parse the selected source code files.
 This can also be done interactively, selecting and deselecting files
 anytime. }

interface

uses Classes, Forms, Controls, StdCtrls, ExtCtrls, 
     UTokenParser,
     UMainFormFrame,
     UJADDState;

type
  {A simple page with buttons to parse the selected source code files. This can
   also be done interactively, selecting and deselecting files anytime. }
  TMFParse = class(TMainFormFrame)
    ButtonParse: TButton;
    ButtonManually: TButton;
    CheckBoxKeepCurrentData: TCheckBox;
    procedure ButtonParseClick(Sender: TObject);
  private
    //if data has been parsed on this page
    FParsed: Boolean;
    //if data has been successfully parsed on this page
    FSuccesfullyParsed: Boolean;
  protected
    //Called when the list of parsed file changes.
    procedure StateFileListChanged(State: TJADDState); override;
  public
  end;




//Handles a parsing error by showing the error message and maybe the position
//of the error in the source code.
procedure HandleParsingError(E: EParseException;
                             HelpContext: THelpContext;
                             State: TJADDState;
                             ShowSourceCode: TShowSourceCallBack;
                             Sender: TMainFormFrame);

implementation

{$R *.dfm}

uses SysUtils, Dialogs,
     UAddInteractively;





{Handles a parsing error by showing the error message and maybe the position of
 the error in the source code.
~param E              the exception object of the error with all information
~param HelpContext    the help context for showing the error message
~param State          the object hold the whole state
~param ShowSourceCode the call back procedure to show a position in the source
                      code
~param Sender         the form in which the error occurred, may be nil }
procedure HandleParsingError(E: EParseException;
                             HelpContext: THelpContext;
                             State: TJADDState;
                             ShowSourceCode: TShowSourceCallBack;
                             Sender: TMainFormFrame);
var       Msg               :String; //content of the error message to be shown                             
begin
 //file known and added?
 if assigned(E.EffectiveFile) and
    (State.FileList.IsIn(E.EffectiveFile) or
     State.FileList.IsIncluded(E.EffectiveFile)) then
  if assigned(E.TheFile) and State.FileList.IsIn(E.TheFile) then
   ShowSourceCode(Sender, nil, E.TheFile, E.ErrorPosition,
                               E.EffectiveFile, E.EffectiveErrorPosition)
  else
   ShowSourceCode(Sender, nil, E.EffectiveFile, E.EffectiveErrorPosition,
                               E.EffectiveFile, E.EffectiveErrorPosition);


 Msg := Format('Error while parsing: Kind of Error: %s'#13,
               [ExceptTypeName[E.ExceptType]]);
 if E.EffectiveFile <> E.TheFile then
  Msg := Msg + Format('in included file at:'#13'%d:%d:%s'#13'%s'#13'included by:'#13,
                      [E.EffectiveErrorPosition.Row,
                       E.EffectiveErrorPosition.Column,
                       E.EffectiveFile.InternalFileName,
                       E.EffectiveFile.FilePath]);
 Msg := Msg + Format('%d:%d:%s'#13'%s'#13,
                     [E.ErrorPosition.Row, E.ErrorPosition.Column,
                      E.TheFile.InternalFileName, E.TheFile.FilePath]);
 Msg := Msg + E.Message;

 //and show the error message
 MessageDlg(Msg, mtError, [mbOK], HelpContext);
end;






{Called when the list of parsed file changes.
~param State the state that has been changed }
procedure TMFParse.StateFileListChanged(State: TJADDState);
begin
 //current parsed data available and complete and not already kept?
 CheckBoxKeepCurrentData.Enabled := assigned(State.FileList) and
                                    State.CompletelyParsed and
                                    (State.CurrentDataKeptIndex = -1);
 //current parsed data already kept?
 CheckBoxKeepCurrentData.Checked := assigned(State.FileList) and
                                    State.CompletelyParsed and
                                    (State.CurrentDataKeptIndex <> -1);
end;





{Called when one of the buttons to parse source code files is clicked.
~param Sender the sender of the event, ~[link ButtonParse] or
              ~[link ButtonManually] }
procedure TMFParse.ButtonParseClick(Sender: TObject);
          //if the files should be parsed interactively
var       Interactively            :Boolean;
begin
 //if data valid, not yet kept and should be kept
 if assigned(State.FileList) and State.CompletelyParsed and
    (State.CurrentDataKeptIndex = -1) and CheckBoxKeepCurrentData.Checked then
  State.KeepCurrentData;                   //keep the current parsed data

 FParsed := True;                        //tried to parse source code files
 FSuccesfullyParsed := False;            //not successful yet

 Interactively := Sender <> ButtonParse; //should be parsed interactively?
 State.StartParsing(Interactively);      //start the parsing
 try
   //show dialog to select the files interactively if applicable
   if not Interactively or AddFilesInteractively(State.FileList) then
    begin
     try
       FSuccesfullyParsed := State.DoParsing; //parse the source code files
     except
       on E: EParseException do               //in case of a parse error
        HandleParsingError(E, ButtonParse.HelpContext,
                           State, ShowSourceCode, Self);
       else
        raise;                        //unknown/system error? => not handled
     end; //try .. except

    end; //if not Interactively or AddFilesInteractively(State.FileList)


 finally
  State.FinishParsing;                   //finish the parsing; free resources
 end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -