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

📄 skyparser.pas

📁 SkyEdit是一个可用彩色语法来显示及编辑各种开发语言源代码的编辑器控件。
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{*******************************************************************************
*                 TSkyParser  --  SkyEdit的彩色语法显示支持类                  *
*                                                                              *
*     功能:为SkyEdit提供语法定义及彩色显示所需的字体、前景/背景色定义支持     *
*     版本:0.95 beta                                                          *
*     作者:顾中军                                                             *
*     实现:                                                                   *
*         因为SkyParser比较简单,它只是为支持SkyEdit而写,无论使用何种语言,   *
*     SkyParser均可处理,因为涉及到语言特性及显示的部分已由SkyEdit处理了;     *
*         从2004.04.16第一个版本实现直到如今,SkyParser一直伴随着SkyEdit的     *
*     成长而逐渐完善,我相信即使将来对SkyEdit进行较大改进时,SkyParser也将     *
*     不会有太多的变化了。                                                     *
*                                                                              *
*     说明:                                                                   *
*         TSkyParser需与TSkyEdit配合方能发挥作用,它是SkyEdit控件的重要组成    *
*     部分                                                                     *
*                                                                              *
*     版权声明:                                                               *
*         SkyEdit源码公开,你可以在它的基础上进行任何改进,并且你可以将它用    *
*     于任何场合;                                                             *
*         如果你有更好的改进,别忘了给我发一份啊;                             *
*         此外,如果你是在它的基础上改进,请保留我写的文本及说明,毕竟我花     *
*     了不少精力和时间,请尊重我的劳动成果;另外我希望你能将改进的代码公布     *
*     出来,多交流才能更快地进步嘛;                                           *
*         因为SkyEdit的编写过程中,我从mwCustomEdit 0.62 版的源码中学到了不    *
*     少东西,在此向它的作者们表示最衷心的感谢(以下TCustomSkyEdit的实现处     *
*     有进一步的说明);当然,由于Borland提供了几乎所有的VCL源码,使得我从     *
*     中学到了很多,故而在此对Borland及为Borland作出贡献的人们表示最诚挚的     *
*     祝福,祝Borland开发工具之树常青;                                        *
*                                                                              *
*                                                                              *
*         虽然SkyEdit与一些更专业的编辑控件相比显得苗条了些,不过它还是实现    *
*     一个编辑器所应有的基本功能;因此作者在这里希望它能给想要学习和正在学     *
*     习编写控件的朋友一点帮助。                                               *
*         最后,愿与所有喜爱软件开发的朋友们共勉:让世界因软件而变得更美好!   *
*                                                                              *
*     网站:不好意思,还没建立自己的网站呢                                     *
*     妹儿:iamdream@citiz.net                                                 *
*******************************************************************************}

unit SkyParser;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics;

const
  ALPHA    = ['a'..'z', 'A'..'Z', '_'];
  DIGIT    = ['0'..'9'];
  HEXDIGIT = ['0'..'9', 'a'..'f', 'A'..'F'];

type
  TSkySymbols = set of Char;

  TSkySyntaxType =
     (sstNone,        sstEscapeChar,  sstMacroWrapChar, sstLineComments,
      sstCommentOns,  sstCommentOffs, sstDelimiters,    sstMacroSymbols,
      sstStringChars, sstCharacters,  sstNormalText,    sstHotLink,
      sstInt_1,       sstInt_2,       sstInt_3,         sstInt_4,
      sstInt_5,       sstInt_6,       sstFloat,         sstFloat_x,
      sstWords_1,     sstWords_2,     sstWords_3,       sstWords_4,
      sstWords_5,     sstWords_6,     sstWords_7,       sstWords_8);

  TSkySyntaxAttr = class(TPersistent)
  private
    FUseDefBkgColor: Boolean;
    FUseDefFrgColor: Boolean;
    FBkgColor:       TColor;
    FFrgColor:       TColor;
    FStyle:          TFontStyles;
    FName:           String;
  protected
  public
    procedure Assign(Source: TPersistent); override;

    constructor Create; overload;
    constructor Create(Name: String); overload;
  published
    property UseDefBkgColor: Boolean read FUseDefBkgColor write FUseDefBkgColor;
    property UseDefFrgColor: Boolean read FUseDefFrgColor write FUseDefFrgColor;
    property BkgColor:       TColor      read FBkgColor write FBkgColor;
    property FrgColor:       TColor      read FFrgColor write FFrgColor;
    property Name:           String      read FName     write FName;
    property Style:          TFontStyles read FStyle    write FStyle;
  end;

  PSkySyntaxAttr = ^TSkySyntaxAttr;

  TCustomSkyParser = class(TComponent)
  private
    { Private declarations }
    FCaseSensitive:     Boolean;        //区分大小写?

    FEscapeChar:        Char;           //字符串忽略符(换行用)
    FMacroWrapChar:     Char;           //宏换行符(指预处理)

    FLineComments:      TStrings;       //单行注释符
    FBlockCommentOns:   TStrings;       //多行注释开始符
    FBlockCommentOffs:  TStrings;       //多行注释结束符(对开始符配对使用!)
    FDelimiters:        String;         //分隔符
    FMacroSymbols:      String;         //宏指示符(指预处理)
    FStringChars:       String;         //字符串指示符
    FCharacters:        Char;           //单个字符指示符
    //FNumberSymbols:     String;         数字串指示符(位于单词首,且其后为数字)

    FDelimiterSymbols:  TSkySymbols;    //分隔符集合
    FMacroNoteSymbols:  TSkySymbols;    //宏指示符集合
    FStringSymbols:     TSkySymbols;    //字符串指示符集合

    FWords_1:           TStrings;       //关键字列表_1
    FWords_2:           TStrings;       //关键字列表_2
    FWords_3:           TStrings;       //关键字列表_3
    FWords_4:           TStrings;       //关键字列表_4
    FWords_5:           TStrings;       //关键字列表_5
    FWords_6:           TStrings;       //关键字列表_6
    FWords_7:           TStrings;       //关键字列表_7
    FWords_8:           TStrings;       //关键字列表_8

    FNormalTextAttr:    TSkySyntaxAttr; //普通文本显示属性
    FCommentsAttr:      TSkySyntaxAttr; //注释显示属性
    FDelimitersAttr:    TSkySyntaxAttr; //分隔符显示属性
    FMacrosAttr:        TSkySyntaxAttr; //宏显示属性(指预处理)
    FStringsAttr:       TSkySyntaxAttr; //字符串显示属性
    FCharAttr:          TSkySyntaxAttr; //单个字符显示属性
    FSpaceAttr:         TSkySyntaxAttr; //空白处显示属性
    FHotLinkAttr:       TSkySyntaxAttr; //热点显示属性(含URL)

    FInt_1_Chars:       String;         //整数一之字符集串
    FInt_2_Chars:       String;         //整数二之字符集串
    FInt_3_Chars:       String;         //整数三之字符集串
    FInt_4_Chars:       String;         //整数四之字符集串
    FFloat_Chars:       String;         //浮点数之字符集串

    FInt_1_Charset:     TSkySymbols;    //整数一之字符集
    FInt_2_Charset:     TSkySymbols;    //整数二之字符集
    FInt_3_Charset:     TSkySymbols;    //整数三之字符集
    FInt_4_Charset:     TSkySymbols;    //整数四之字符集
    FFloat_Charset:     TSkySymbols;    //浮点数之字符集 
    //以下FInt_1_He..4..及FFloat_He..用于简单确定各种表示方法的数值
    FInt_1_HeadChar:    Char;
    FInt_2_HeadChar:    Char;
    //FInt_3_HeadChar:    Char;           常用十进数以数字开始,故无需HeadChar
    FInt_4_HeadChar:    Char;
    FFloat_HeadChar:    Char;
    //以下FInt_1..4_Attr均用于整数的显示(如二、八、十、十六进制数的显示)
    FInt_1_Attr:        TSkySyntaxAttr; //第一种整数显示属性
    FInt_2_Attr:        TSkySyntaxAttr; //第二种整数显示属性
    FInt_3_Attr:        TSkySyntaxAttr; //第三种整数显示属性 <默认为常用十进数>
    FInt_4_Attr:        TSkySyntaxAttr; //第四种整数显示属性
    FFloatAttr:         TSkySyntaxAttr; //浮点数显示属性

    FWords_1_Attr:      TSkySyntaxAttr; //关键字_1 显示属性
    FWords_2_Attr:      TSkySyntaxAttr; //关键字_2 显示属性
    FWords_3_Attr:      TSkySyntaxAttr; //关键字_3 显示属性
    FWords_4_Attr:      TSkySyntaxAttr; //关键字_4 显示属性
    FWords_5_Attr:      TSkySyntaxAttr; //关键字_5 显示属性
    FWords_6_Attr:      TSkySyntaxAttr; //关键字_6 显示属性
    FWords_7_Attr:      TSkySyntaxAttr; //关键字_7 显示属性
    FWords_8_Attr:      TSkySyntaxAttr; //关键字_8 显示属性

    FFileExtentions:    TStrings;       //关联文件类型
    FLanguageName:      String;         //关联语言名称(如:C++)

    FCurrSyntaxAttr:    PSkySyntaxAttr; //当前活动显示属性指针

    FAlphabet:          TSkySymbols;    //组成单词的字母表(默认SkyEdit.ALPHA)
    FAlphabetChars:     String;         //组成单词的字母表

    procedure SetCaseSensitive(Value: Boolean);
    procedure SetDelimiters(const Value: String);
    procedure SetMacroSymbols(const Value: String);
    procedure SetStringChars(const Value: String);

    procedure SetLineComments(Value: TStrings);
    procedure SetBlockCommentOns(Value: TStrings);
    procedure SetBlockCommentOffs(Value: TStrings);
    procedure SetWords_1(Value: TStrings);
    procedure SetWords_2(Value: TStrings);
    procedure SetWords_3(Value: TStrings);
    procedure SetWords_4(Value: TStrings);
    procedure SetWords_5(Value: TStrings);
    procedure SetWords_6(Value: TStrings);
    procedure SetWords_7(Value: TStrings);
    procedure SetWords_8(Value: TStrings);
    procedure SetFileExtentions(Value: TStrings);

    procedure SetInt_1_Chars(const Value: String);
    procedure SetInt_2_Chars(const Value: String);
    procedure SetInt_3_Chars(const Value: String);
    procedure SetInt_4_Chars(const Value: String);
    procedure SetFloat_Chars(const Value: String);

    procedure SetAlphabetChars(const Value: String);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;

    function GetSyntaxTypeByWord(const sWord: String; var idx: Integer): TSkySyntaxType;
    function GetCurrSyntaxAttr: TSkySyntaxAttr;
    function IsStringSymbols(ch: Char): Boolean;
    function IsMacroSymbols(ch: Char): Boolean;

    property Int_1_Charset: TSkySymbols read FInt_1_Charset; //整数一之字符集
    property Int_2_Charset: TSkySymbols read FInt_2_Charset; //整数二之字符集
    property Int_3_Charset: TSkySymbols read FInt_3_Charset; //整数三之字符集
    property Int_4_Charset: TSkySymbols read FInt_4_Charset; //整数四之字符集
    property Float_Charset: TSkySymbols read FFloat_Charset; //浮点数之字符集

    property Alphabet: TSkySymbols read FAlphabet write FAlphabet;

  published
    { Published declarations }
    property CaseSensitive:    Boolean  read FCaseSensitive    write SetCaseSensitive ;

    property EscapeChar:       Char     read FEscapeChar       write FEscapeChar      ;
    property MacroWrapChar:    Char     read FMacroWrapChar    write FMacroWrapChar   ;

    property LineComments:     TStrings read FLineComments     write SetLineComments     ;
    property BlockCommentOns:  TStrings read FBlockCommentOns  write SetBlockCommentOns  ;
    property BlockCommentOffs: TStrings read FBlockCommentOffs write SetBlockCommentOffs ;
    property Delimiters:       String   read FDelimiters       write SetDelimiters     ;
    property MacroSymbols:     String   read FMacroSymbols     write SetMacroSymbols   ;
    property StringChars:      String   read FStringChars      write SetStringChars    ;
    property Characters:       Char     read FCharacters       write FCharacters       ;
    //property NumberSymbols:    String   read FNumberSymbols    write FNumberSymbols    ;

    property Words_1:          TStrings read FWords_1 write SetWords_1 ;
    property Words_2:          TStrings read FWords_2 write SetWords_2 ;
    property Words_3:          TStrings read FWords_3 write SetWords_3 ;
    property Words_4:          TStrings read FWords_4 write SetWords_4 ;
    property Words_5:          TStrings read FWords_5 write SetWords_5 ;
    property Words_6:          TStrings read FWords_6 write SetWords_6 ;
    property Words_7:          TStrings read FWords_7 write SetWords_7 ;
    property Words_8:          TStrings read FWords_8 write SetWords_8 ;

    property NormalTextAttr:   TSkySyntaxAttr read FNormalTextAttr write FNormalTextAttr ;
    property CommentsAttr:     TSkySyntaxAttr read FCommentsAttr   write FCommentsAttr   ;
    property DelimitersAttr:   TSkySyntaxAttr read FDelimitersAttr write FDelimitersAttr ;
    property MacrosAttr:       TSkySyntaxAttr read FMacrosAttr     write FMacrosAttr     ;
    property StringsAttr:      TSkySyntaxAttr read FStringsAttr    write FStringsAttr    ;
    property CharAttr:         TSkySyntaxAttr read FCharAttr       write FCharAttr       ;
    property SpaceAttr:        TSkySyntaxAttr read FSpaceAttr      write FSpaceAttr      ;
    property HotLinkAttr:      TSkySyntaxAttr read FHotLinkAttr    write FHotLinkAttr    ;

    property Int_1_Chars:      String read FInt_1_Chars write SetInt_1_Chars; //整数一之字符集串
    property Int_2_Chars:      String read FInt_2_Chars write SetInt_2_Chars; //整数二之字符集串
    property Int_3_Chars:      String read FInt_3_Chars write SetInt_3_Chars; //整数三之字符集串
    property Int_4_Chars:      String read FInt_4_Chars write SetInt_4_Chars; //整数四之字符集串
    property Float_Chars:      String read FFloat_Chars write SetFloat_Chars; //浮点数之字符集串

    property Int_1_HeadChar:   Char read FInt_1_HeadChar write FInt_1_HeadChar;
    property Int_2_HeadChar:   Char read FInt_2_HeadChar write FInt_2_HeadChar;
    //property Int_3_HeadChar:   Char read FInt_3_HeadChar write FInt_3_HeadChar;  常用十进数以数字开始,故无需HeadChar
    property Int_4_HeadChar:   Char read FInt_4_HeadChar write FInt_4_HeadChar;
    property Float_HeadChar:   Char read FFloat_HeadChar write FFloat_HeadChar;
    
    property Int_1_Attr:       TSkySyntaxAttr read FInt_1_Attr   write FInt_1_Attr ;
    property Int_2_Attr:       TSkySyntaxAttr read FInt_2_Attr   write FInt_2_Attr ;
    property Int_3_Attr:       TSkySyntaxAttr read FInt_3_Attr   write FInt_3_Attr ;
    property Int_4_Attr:       TSkySyntaxAttr read FInt_4_Attr   write FInt_4_Attr ;
    property FloatAttr:        TSkySyntaxAttr read FFloatAttr    write FFloatAttr  ;

    property Words_1_Attr:     TSkySyntaxAttr read FWords_1_Attr write FWords_1_Attr ;

⌨️ 快捷键说明

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