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

📄 synhighlighterhc11.pas

📁 SynEditStudio delphi 代码编辑器
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-------------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: SynHighlighterHC11.pas, released 2000-04-21.
The Original Code is based on the CIHC11Syn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Nils Springob.
All Rights Reserved.

Contributors to the SynEdit and mwEdit projects are listed in the
Contributors.txt file.

Alternatively, the contents of this file may be used under the terms of the
GNU General Public License Version 2 or later (the "GPL"), in which case
the provisions of the GPL are applicable instead of those above.
If you wish to allow use of your version of this file only under the terms
of the GPL and not to allow others to use your version of this file
under the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your version
of this file under either the MPL or the GPL.

$Id: SynHighlighterHC11.pas,v 1.14 2005/01/28 16:53:22 maelh Exp $

You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net

Known Issues:
-------------------------------------------------------------------------------}
{
@abstract(Provides a 68HC11 Assembler Language syntax highlighter for SynEdit)
@author(Nils Springob <delphi.nils@crazy-idea.de>, converted to SynEdit by Bruno Mikkelsen <btm@scientist.com>)
@created(January 2000, converted to SynEdit April 21, 2000)
@lastmod(2000-06-23)
The SynHighlighterHC11 unit provides SynEdit with a 68HC11 Assembler (.asm) highlighter.
The highlighter supports all 68HC11 op codes.
Thanks to Martin Waldenburg, David Muir, Hideo Koiso and Nick Hoddinott.
}

{$IFNDEF QSYNHIGHLIGHTERHC11}
unit SynHighlighterHC11;
{$ENDIF}

{$I SynEdit.inc}

interface

uses
{$IFDEF SYN_CLX}
  QGraphics,
  QSynEditHighlighter,
  QSynEditTypes,
{$ELSE}
  Graphics,
  SynEditHighlighter,
  SynEditTypes,
{$ENDIF}
  SysUtils,
  Classes;

const
  KeyWordCount = 149;
  DirectiveCount = 6;

type
  TtkTokenKind = (tkComment, tkDirective, tkIdentifier, tkKey, tkNull, tkNumber,
    tkSpace, tkString, tkSymbol, tkUnknown);

  TkwKeyWordType = (kwNone, kwOperand, kwOperandOver, kwNoOperand);

  PHashListEntry = ^THashListEntry;
  THashListEntry = record
    Next: PHashListEntry;
    Token: String;
    Kind: TtkTokenKind;
    Op: Boolean;
  end;

  TProcTableProc = procedure of Object;

  TSynHC11Syn = class(TSynCustomHighLighter)
  private
    fLine: PChar;
    fLineNumber: integer;
    fProcTable: array[#0..#255] of TProcTableProc;
    Run: LongInt;
    fStringLen: Integer;
    fToIdent: PChar;
    fTokenPos: Integer;
    FTokenID: TtkTokenKind;
    FKeyWordType: TkwKeyWordType;
    fCommentAttri: TSynHighlighterAttributes;
    fDirecAttri: TSynHighlighterAttributes;
    fIdentifierAttri: TSynHighlighterAttributes;
    fInvalidAttri: TSynHighlighterAttributes;
    fKeyAttri: TSynHighlighterAttributes;
    fNumberAttri: TSynHighlighterAttributes;
    fSpaceAttri: TSynHighlighterAttributes;
    fStringAttri: TSynHighlighterAttributes;
    fSymbolAttri: TSynHighlighterAttributes;

    fHashArray: array[0..DirectiveCount+KeyWordCount] of THashListEntry;
    fHashList: array[#0..#255] of PHashListEntry;
    fHashArrayIndex: integer;

    function KeyHash(ToHash: PChar): char;
    function KeyComp(const aKey: string): Boolean;

    procedure SymAsciiCharProc;
    procedure SymbolProc;
    procedure SymDollarProc;
    procedure SymCRProc;
    procedure SymIdentProc;
    procedure SymLFProc;
    procedure SymPercentProc;
    procedure SymNullProc;
    procedure SymNumberProc;
    procedure SymSpaceProc;
    procedure SymStarProc;
    procedure SymStringProc;
    procedure SymUnknownProc;

    procedure InitIdent;
    procedure MakeMethodTables;
    procedure AddHashEntry(NewToken: String; NewKind: TtkTokenKind);
    function IdentKind(MayBe: PChar): TtkTokenKind;
  protected
    function GetIdentChars: TSynIdentChars; override;
    function GetSampleSource: string; override;
    function IsFilterStored: Boolean; override;
  public
    class function GetLanguageName: string; override;
  public
    constructor Create(AOwner: TComponent); override;
    function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
      override;
    function GetEol: Boolean; override;
    function GetTokenID: TtkTokenKind;
    procedure SetLine(NewValue: String; LineNumber:Integer); override;
    function GetToken: String; override;
    function GetTokenAttribute: TSynHighlighterAttributes; override;
    function GetTokenKind: integer; override;
    function GetTokenPos: Integer; override;
    procedure Next; override;
  published
    property CommentAttri: TSynHighlighterAttributes read fCommentAttri
      write fCommentAttri;
    property DirecAttri: TSynHighlighterAttributes read fDirecAttri
      write fDirecAttri;
    property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
      write fIdentifierAttri;
    property InvalidAttri: TSynHighlighterAttributes read fInvalidAttri
      write fInvalidAttri;
    property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
    property NumberAttri: TSynHighlighterAttributes read fNumberAttri
      write fNumberAttri;
    property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
      write fSpaceAttri;
    property StringAttri: TSynHighlighterAttributes read fStringAttri
      write fStringAttri;
    property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
      write fSymbolAttri;
  end;

implementation

uses
{$IFDEF SYN_CLX}
  QSynEditStrConst;
{$ELSE}
  SynEditStrConst;
{$ENDIF}

var
  Identifiers: array[#0..#255] of ByteBool;

const
  KeyWords: array[1..KeyWordCount] of string = (
    'ABA', 'ABX', 'ABY', 'ADCA_', 'ADCB_', 'ADDA_', 'ADDB_', 'ADDD_', 'ANDA_',
    'ANDB_', 'ASLA', 'ASLB', 'ASL_', 'ASLD', 'ASRA', 'ASRB', 'ASR_', 'BCC_',
    'BCLR_', 'BCS_', 'BEQ_', 'BGE_', 'BGT_', 'BHI_', 'BHS_', 'BITA_', 'BITB_',
    'BLE_', 'BLO_', 'BLS_', 'BLT_', 'BMI_', 'BNE_', 'BPL_', 'BRA_', 'BRCLR_',
    'BRN_', 'BRSET_', 'BSET_', 'BSR_', 'BVC_', 'BVS_', 'CBA', 'CLC', 'CLI',
    'CLRA', 'CLRB', 'CLR_', 'CLV', 'CMPA_', 'CMPB_', 'COMA', 'COMB', 'COM_',
    'CPD_', 'CPX_', 'CPY_', 'DAA', 'DECA', 'DECB', 'DEC_', 'DES', 'DEX', 'DEY',
    'EORA_', 'EORB_', 'FDIV', 'IDIV', 'INCA', 'INCB', 'INC_', 'INS', 'INX',
    'INY', 'JMP_', 'JSR_', 'LDAA_', 'LDAB_', 'LDD_', 'LDS_', 'LDX_', 'LDY_',
    'LSLA', 'LSLB', 'LSL_', 'LSLD', 'LSRA', 'LSRB', 'LSR_', 'LSRD', 'MUL',
    'NEGA', 'NEGB', 'NEG_', 'NOP', 'ORAA_', 'ORAB_', 'PSHA', 'PSHB', 'PSHX',
    'PSHY', 'PULA', 'PULB', 'PULX', 'PULY', 'ROLA', 'ROLB', 'ROL_', 'RORA',
    'RORB', 'ROR_', 'RTI', 'RTS', 'SBA', 'SBCA_', 'SBCB_', 'SEC', 'SEI', 'SEV',
    'STAA_', 'STAB_', 'STD_', 'STOP', 'STS_', 'STX_', 'STY_', 'SUBA_', 'SUBB_',
    'SUBD_', 'SWI', 'TAB', 'TAP', 'TBA', 'TEST', 'TPA', 'TSTA', 'TSTB', 'TST_',
    'TSX', 'TSY', 'TXS', 'TYS', 'WAI', 'XGDX', 'XGDY', // end commands
    'FCC_','FCB_','BSZ_','FDB_' // codegenerating directives
    );

  Directives: array[1..DirectiveCount] of string = (
    'EQU_', 'OPT_', 'PAGE', 'ORG_', 'RMB_', 'END'  // directives
    );
procedure MakeIdentTable;
var
  I: Char;
begin
  for I := #0 to #255 do
  begin
    Case I of
      '_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
    else Identifiers[I] := False;
    end;
  end;
end;


procedure TSynHC11Syn.AddHashEntry(NewToken: String; NewKind: TtkTokenKind);
var
  Hash: char;
  actEntryPtr: ^PHashListEntry;
  actEntry: PHashListEntry;
begin
  with fHashArray[fHashArrayIndex] do
  begin
    Op := false;
    if Pos('_', NewToken) <> 0 then begin
      Delete(NewToken, Length(NewToken), 1);
      Op := true;
    end;
    Token := NewToken;
    Kind := NewKind;
    Hash := KeyHash(PChar(NewToken));
    actEntryPtr := @fHashList[Hash];
    actEntry := fHashList[Hash];
    while (actEntry <> nil) do
    begin
      actEntryPtr := @actEntry.Next;
      actEntry := actEntry.Next;
    end;
    Next := nil;
  end;
  actEntryPtr^ := @fHashArray[fHashArrayIndex];
  inc(fHashArrayIndex);
end;

procedure TSynHC11Syn.InitIdent;
var
  i: integer;
  c: char;
begin
  // initialize list
  fHashArrayIndex := 0;
  for c := #0 to #255 do
    fHashList[c] := nil;
  // put all keywords into the list
  for i := 1 to KeyWordCount do
    AddHashEntry(KeyWords[i], tkKey);
  // put all directives into the list
  for i := 1 to DirectiveCount do
    AddHashEntry(Directives[i], tkDirective);
end;

function TSynHC11Syn.KeyHash(ToHash: PChar): char;
begin
  Result := #0;
  while ToHash^ in ['_', '0'..'9', 'a'..'z', 'A'..'Z'] do
  begin
    Result := char(byte(Result) + byte(ToHash^));
    inc(ToHash);
  end;
  fStringLen := ToHash - fToIdent;
end; { KeyHash }

function TSynHC11Syn.KeyComp(const aKey: String): Boolean;
var
  I: Integer;
  Temp: PChar;
begin
  Temp := fToIdent;
  if Length(aKey) = fStringLen then
  begin
    Result := True;
    for i := 1 to fStringLen do
    begin
      if Temp^ <> aKey[i] then
      begin
        Result := False;
        break;
      end;
      inc(Temp);
    end;
  end else Result := False;
end; { KeyComp }

function TSynHC11Syn.IdentKind(MayBe: PChar): TtkTokenKind;
var
  Hash: char;
  actEntry: PHashListEntry;
begin
  fToIdent := MayBe;
  Hash := KeyHash(MayBe);

⌨️ 快捷键说明

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