root/Cheat Engine/SynEdit/Source/SynHighlighterAA.pas @ 309

Revision 309, 31.6 kB (checked in by dark_byte, 8 months ago)

bugfixes for the heaplist and memory dissect

Line 
1{------------------------------------------------------------------------------
2The contents of this file are subject to the Mozilla Public License
3Version 1.1 (the "License"); you may not use this file except in compliance
4with the License. You may obtain a copy of the License at
5http://www.mozilla.org/MPL/
6
7Software distributed under the License is distributed on an "AS IS" basis,
8WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9the specific language governing rights and limitations under the License.
10
11The Original Code is: SynHighlighterPas.pas, released 2000-04-17.
12The Original Code is based on the mwPasSyn.pas file from the
13mwEdit component suite by Martin Waldenburg and other developers, the Initial
14Author of this file is Martin Waldenburg.
15Portions created by Martin Waldenburg are Copyright (C) 1998 Martin Waldenburg.
16All Rights Reserved.
17
18Contributors to the SynEdit and mwEdit projects are listed in the
19Contributors.txt file.
20
21Alternatively, the contents of this file may be used under the terms of the
22GNU General Public License Version 2 or later (the "GPL"), in which case
23the provisions of the GPL are applicable instead of those above.
24If you wish to allow use of your version of this file only under the terms
25of the GPL and not to allow others to use your version of this file
26under the MPL, indicate your decision by deleting the provisions above and
27replace them with the notice and other provisions required by the GPL.
28If you do not delete the provisions above, a recipient may use your version
29of this file under either the MPL or the GPL.
30
31$Id: SynHighlighterPas.pas,v 1.30 2005/01/28 16:53:24 maelh Exp $
32
33You may retrieve the latest version of this file at the SynEdit home page,
34located at http://SynEdit.SourceForge.net
35
36
37@abstract(Provides a AutoAssembler syntax highlighter for SynEdit)
38
39
40}
41
42{$IFNDEF QSYNHIGHLIGHTERPAS}
43unit SynHighlighterAA;
44{$ENDIF}
45
46{$I SynEdit.inc}
47
48interface
49
50uses
51{$IFDEF SYN_CLX}
52  QGraphics,
53  QSynEditTypes,
54  QSynEditHighlighter,
55{$ELSE}
56  Windows,
57  Graphics,
58  SynEditTypes,
59  SynEditHighlighter,
60{$ENDIF}
61  SysUtils,
62  Classes,
63  assemblerunit;
64
65type
66  TtkTokenKind = (tkAsm, tkComment, tkIdentifier, tkKey, tkNull, tkNumber,
67    tkSpace, tkString, tkSymbol, tkUnknown, tkFloat, tkHex, tkDirec, tkChar,
68    tkRegister);
69
70  TRangeState = (rsANil, rsAnsi, rsAnsiAsm, rsAsm, rsBor, rsBorAsm, rsProperty,
71    rsExports, rsDirective, rsDirectiveAsm, rsUnKnown);
72
73  TProcTableProc = procedure of object;
74
75  PIdentFuncTableFunc = ^TIdentFuncTableFunc;
76  TIdentFuncTableFunc = function: TtkTokenKind of object;
77
78  TAutoAssemblerVersion = (dvAutoAssembler1, dvAutoAssembler2, dvAutoAssembler3, dvAutoAssembler4, dvAutoAssembler5,
79    dvAutoAssembler6, dvAutoAssembler7, dvAutoAssembler8, dvAutoAssembler2005);
80
81const
82  LastAutoAssemblerVersion = dvAutoAssembler2005;
83
84type
85  TSynAASyn = class(TSynCustomHighlighter)
86  private
87    fAsmStart: Boolean;
88    fRange: TRangeState;
89    fLine: PChar;
90    fLineNumber: Integer;
91    fProcTable: array[#0..#255] of TProcTableProc;
92    Run: LongInt;
93    fStringLen: Integer;
94    fToIdent: PChar;
95    fIdentFuncTable: array[0..222] of TIdentFuncTableFunc;
96    fTokenPos: Integer;
97    FTokenID: TtkTokenKind;
98    fStringAttri: TSynHighlighterAttributes;
99    fCharAttri: TSynHighlighterAttributes;
100    fNumberAttri: TSynHighlighterAttributes;
101    fFloatAttri: TSynHighlighterAttributes;
102    fHexAttri: TSynHighlighterAttributes;
103    fKeyAttri: TSynHighlighterAttributes;
104    fSymbolAttri: TSynHighlighterAttributes;
105    fAsmAttri: TSynHighlighterAttributes;
106    fCommentAttri: TSynHighlighterAttributes;
107    fDirecAttri: TSynHighlighterAttributes;
108    fIdentifierAttri: TSynHighlighterAttributes;
109    fSpaceAttri: TSynHighlighterAttributes;
110    fRegisterAttri: TSynHighlighterAttributes;
111    fAutoAssemblerVersion: TAutoAssemblerVersion;
112    fPackageSource: Boolean;
113    function KeyHash(ToHash: PChar): Integer;
114    function KeyComp(const aKey: string): Boolean;
115    function Func9: TtkTokenKind; //ah
116    function Func10: TtkTokenKind; //bh
117    function Func11: TtkTokenKind; //ch
118    function Func12: TtkTokenKind; //dh
119    function Func13: TtkTokenKind; //di / al
120    function Func14: TtkTokenKind; //bl
121    function Func15: TtkTokenKind; //cl
122    function Func16: TtkTokenKind; //dl
123    function Func18: TtkTokenKind; //edi  / bp
124    function Func23: TtkTokenKind; //ebp
125    function Func25: TtkTokenKind; //ax / 25
126    function Func26: TtkTokenKind; //bx
127    function Func27: TtkTokenKind; //cx
128    function Func28: TtkTokenKind; //dx / si
129    function Func30: TtkTokenKind; //eax / eip
130    function Func31: TtkTokenKind; //ebx
131    function Func32: TtkTokenKind; //ecx
132    function Func33: TtkTokenKind; //edx / esi
133    function Func35: TtkTokenKind; //sp
134    function Func39: TtkTokenKind; //enable
135    function Func40: TtkTokenKind; //esp
136    function Func43: TtkTokenKind; //alloc /define
137    function Func52: TtkTokenKind; //dealloc / disable
138    function Func54: TtkTokenKind; //kalloc
139    function Func59: TtkTokenKind; //readmem   
140    function Func68: TtkTokenKind; //include
141    function Func82: TtkTokenKind; //assert
142    function Func92: TtkTokenKind; //globalalloc
143    function Func101: TtkTokenKind; //fullaccess/loadbinary
144    function Func108: TtkTokenKind; //CreateThread
145    function Func117: TtkTokenKind; //loadlibrary
146    function Func187: TtkTokenKind; //registersymbol
147    function Func222: TtkTokenKind; //unregistersymbol
148
149    function AltFunc: TtkTokenKind;
150    procedure InitIdent;
151    function getfirsttoken(s: string): string;
152    function IdentKind(MayBe: PChar): TtkTokenKind;
153    procedure MakeMethodTables;
154    procedure AddressOpProc;
155    procedure AsciiCharProc;
156    procedure AnsiProc;
157    procedure BorProc;
158    procedure BraceOpenProc;
159    procedure ColonOrGreaterProc;
160    procedure CRProc;
161    procedure IdentProc;
162    procedure IntegerProc;
163    procedure LFProc;
164    procedure LowerProc;
165    procedure NullProc;
166    procedure NumberProc;
167    procedure PointProc;
168    procedure RoundOpenProc;
169    procedure SemicolonProc;
170    procedure SlashProc;
171    procedure SpaceProc;
172    procedure StringProc;
173    procedure SymbolProc;
174    procedure UnknownProc;
175    procedure SetAutoAssemblerVersion(const Value: TAutoAssemblerVersion);
176    procedure SetPackageSource(const Value: Boolean);
177  protected
178    function GetIdentChars: TSynIdentChars; override;
179    function GetSampleSource: string; override;
180    function IsFilterStored: boolean; override;
181  public
182    class function GetCapabilities: TSynHighlighterCapabilities; override;
183    class function GetLanguageName: string; override;
184  public
185    constructor Create(AOwner: TComponent); override;
186    function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
187      override;
188    function GetEol: Boolean; override;
189    function GetRange: Pointer; override;
190    function GetToken: string; override;
191    function GetTokenAttribute: TSynHighlighterAttributes; override;
192    function GetTokenID: TtkTokenKind;
193    function GetTokenKind: integer; override;
194    function GetTokenPos: Integer; override;
195    procedure Next; override;
196    procedure ResetRange; override;
197    procedure SetLine(NewValue: string; LineNumber:Integer); override;
198    procedure SetRange(Value: Pointer); override;
199    property IdentChars;
200  published
201    property AsmAttri: TSynHighlighterAttributes read fAsmAttri write fAsmAttri;
202    property CommentAttri: TSynHighlighterAttributes read fCommentAttri
203      write fCommentAttri;
204    property DirectiveAttri: TSynHighlighterAttributes read fDirecAttri
205      write fDirecAttri;
206    property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
207      write fIdentifierAttri;
208    property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
209    property RegisterAttri: TSynHighlighterAttributes read fRegisterAttri write fRegisterAttri;
210    property NumberAttri: TSynHighlighterAttributes read fNumberAttri
211      write fNumberAttri;
212    property FloatAttri: TSynHighlighterAttributes read fFloatAttri
213      write fFloatAttri;
214    property HexAttri: TSynHighlighterAttributes read fHexAttri
215      write fHexAttri;
216    property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
217      write fSpaceAttri;
218    property StringAttri: TSynHighlighterAttributes read fStringAttri
219      write fStringAttri;
220    property CharAttri: TSynHighlighterAttributes read fCharAttri
221      write fCharAttri;
222    property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
223      write fSymbolAttri;
224    property AutoAssemblerVersion: TAutoAssemblerVersion read fAutoAssemblerVersion write SetAutoAssemblerVersion
225      default LastAutoAssemblerVersion;
226    property PackageSource: Boolean read fPackageSource write SetPackageSource default True;
227  end;
228
229procedure aa_AddExtraCommand(command:pchar);
230procedure aa_RemoveExtraCommand(command:pchar);
231function isExtraCommand(token:string): boolean;
232
233
234implementation
235
236uses
237{$IFDEF SYN_CLX}
238  QSynEditStrConst;
239{$ELSE}
240  SynEditStrConst;
241{$ENDIF}
242
243var
244  Identifiers: array[#0..#255] of ByteBool;
245  mHashTable: array[#0..#255] of Integer;
246
247  extraCommands: Tstringlist;
248
249procedure aa_AddExtraCommand(command:pchar);
250begin
251  if extraCommands=nil then
252  begin
253    extraCommands:=tstringlist.create;
254    extraCommands.Duplicates:=dupIgnore;
255    extracommands.CaseSensitive:=false;
256  end;
257
258  extraCommands.Add(command);
259end;
260
261procedure aa_RemoveExtraCommand(command:pchar);
262begin
263  if extracommands<>nil then
264  begin
265    extracommands.Delete(extracommands.IndexOf(command));
266    if extracommands.Count=0 then
267      freeandnil(extracommands);
268  end;
269end;
270
271function isExtraCommand(token: string): boolean;
272begin
273  result:=false;
274  if extracommands<>nil then
275    result:=extracommands.IndexOf(token)<>-1;
276end;
277
278
279procedure MakeIdentTable;
280var
281  I, J: Char;
282begin
283  for I := #0 to #255 do
284  begin
285    Case I of
286      '_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
287    else Identifiers[I] := False;
288    end;
289    J := UpCase(I);
290    Case I of
291      'a'..'z', 'A'..'Z', '_': mHashTable[I] := Ord(J) - 64;
292    else mHashTable[Char(I)] := 0;
293    end;
294  end;
295end;
296
297procedure TSynAASyn.InitIdent;
298var
299  I: Integer;
300  pF: PIdentFuncTableFunc;
301begin
302  pF := PIdentFuncTableFunc(@fIdentFuncTable);
303  for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
304    pF^ := AltFunc;
305    Inc(pF);
306  end;
307  fIdentFuncTable[9] := Func9;
308  fIdentFuncTable[10] := Func10;
309  fIdentFuncTable[11] := Func11;
310  fIdentFuncTable[12] := Func12;
311  fIdentFuncTable[13] := Func13;
312  fIdentFuncTable[14] := Func14;
313  fIdentFuncTable[15] := Func15;
314  fIdentFuncTable[16] := Func16;
315  fIdentFuncTable[18] := Func18;
316  fIdentFuncTable[23] := Func23;
317  fIdentFuncTable[25] := Func25;
318  fIdentFuncTable[26] := Func26;
319  fIdentFuncTable[27] := Func27;
320  fIdentFuncTable[28] := Func28;
321  fIdentFuncTable[30] := Func30;
322  fIdentFuncTable[31] := Func31;
323  fIdentFuncTable[32] := Func32;
324  fIdentFuncTable[33] := Func33;
325  fIdentFuncTable[35] := Func35;
326  fIdentFuncTable[39] := Func39;
327  fIdentFuncTable[40] := Func40;
328  fIdentFuncTable[43] := Func43;
329  fIdentFuncTable[52] := Func52;
330  fIdentFuncTable[54] := Func54;
331  fIdentFuncTable[59] := Func59;
332  fIdentFuncTable[68] := Func68;
333  fIdentFuncTable[82] := Func82; 
334  fIdentFuncTable[92] := Func92;
335  fIdentFuncTable[101] := Func101;
336  fIdentFuncTable[108] := Func108;
337  fIdentFuncTable[117] := Func117;
338  fIdentFuncTable[187] := Func187;
339  fIdentFuncTable[222] := Func222;
340end;
341
342function TSynAASyn.KeyHash(ToHash: PChar): Integer;
343begin
344  Result := 0;
345  while ToHash^ in ['a'..'z', 'A'..'Z'] do
346  begin
347    inc(Result, mHashTable[ToHash^]);
348    inc(ToHash);
349  end;
350  if ToHash^ in ['_', '0'..'9'] then inc(ToHash);
351  fStringLen := ToHash - fToIdent;
352end; { KeyHash }
353
354function TSynAASyn.KeyComp(const aKey: string): Boolean;
355var
356  I: Integer;
357  Temp: PChar;
358begin
359  Temp := fToIdent;
360  if Length(aKey) = fStringLen then
361  begin
362    Result := True;
363    for i := 1 to fStringLen do
364    begin
365      if mHashTable[Temp^] <> mHashTable[aKey[i]] then
366      begin
367        Result := False;
368        break;
369      end;
370      inc(Temp);
371    end;
372  end else Result := False;
373end; { KeyComp }
374
375function TSynAASyn.Func9: TtkTokenKind;
376begin
377  if KeyComp('ah') then Result := tkRegister else
378    Result := tkIdentifier;
379end;
380
381function TSynAASyn.Func10: TtkTokenKind;
382begin
383  if KeyComp('bh') then Result := tkRegister else
384    Result := tkIdentifier;
385end;
386
387function TSynAASyn.Func11: TtkTokenKind;
388begin
389  if KeyComp('ch') then Result := tkRegister else
390    Result := tkIdentifier;
391end;
392
393function TSynAASyn.Func12: TtkTokenKind;
394begin
395  if KeyComp('dh') then Result := tkRegister else
396    Result := tkIdentifier;
397end;
398
399function TSynAASyn.Func13: TtkTokenKind;
400begin
401  if KeyComp('di') then Result := tkRegister else
402    if KeyComp('al') then Result := tkRegister else
403      Result := tkIdentifier;
404end;
405
406function TSynAASyn.Func14: TtkTokenKind;
407begin
408  if KeyComp('bl') then Result := tkRegister else
409    Result := tkIdentifier;
410end;
411
412function TSynAASyn.Func15: TtkTokenKind;
413begin
414  if KeyComp('cl') then Result := tkRegister else
415    Result := tkIdentifier;
416end;
417
418function TSynAASyn.Func16: TtkTokenKind;
419begin
420  if KeyComp('dl') then Result := tkRegister else
421    Result := tkIdentifier;
422end;
423
424
425function TSynAASyn.Func18: TtkTokenKind;
426begin
427  if KeyComp('edi') then Result := tkRegister else
428    if KeyComp('bp') then Result := tkRegister else
429      Result := tkIdentifier;
430end;
431
432function TSynAASyn.Func23: TtkTokenKind;
433begin
434  if KeyComp('ebp') then Result := tkRegister else
435    Result := tkIdentifier;
436end;
437
438function TSynAASyn.Func25: TtkTokenKind;
439begin
440  if KeyComp('ax') then Result := tkRegister else
441    if KeyComp('ip') then Result := tkRegister else
442      Result := tkIdentifier;
443end;
444
445function TSynAASyn.Func26: TtkTokenKind;
446begin
447  if KeyComp('bx') then Result := tkRegister else
448    Result := tkIdentifier;
449end;
450
451function TSynAASyn.Func27: TtkTokenKind;
452begin
453  if KeyComp('cx') then Result := tkRegister else
454    Result := tkIdentifier;
455end;
456
457function TSynAASyn.Func28: TtkTokenKind;
458begin
459  if KeyComp('dx') then Result := tkRegister else
460    if KeyComp('si') then Result := tkRegister else
461      Result := tkIdentifier;
462end;
463
464function TSynAASyn.Func30: TtkTokenKind;
465begin
466  if KeyComp('eax') then Result := tkRegister else
467    if KeyComp('eip') then Result := tkRegister else
468      Result := tkIdentifier;
469end;
470
471function TSynAASyn.Func31: TtkTokenKind;
472begin
473  if KeyComp('ebx') then Result := tkRegister else
474    Result := tkIdentifier;
475end;
476
477function TSynAASyn.Func32: TtkTokenKind;
478begin
479  if KeyComp('Label') then Result := tkKey else
480    if KeyComp('ecx') then Result := tkRegister else
481      Result := tkIdentifier;
482end;
483
484function TSynAASyn.Func33: TtkTokenKind;
485begin
486  if KeyComp('edx') then Result := tkRegister else
487    if KeyComp('esi') then Result := tkRegister else
488      Result := tkIdentifier;
489end;
490
491function TSynAASyn.Func35: TtkTokenKind;
492begin
493  if KeyComp('bp') then Result := tkRegister else
494    Result := tkIdentifier;
495end;
496
497function TSynAASyn.Func39: TtkTokenKind; //enable
498begin
499  if KeyComp('enable') then Result := tkspace else
500    Result := tkIdentifier;
501end;
502
503function TSynAASyn.Func40: TtkTokenKind; //enable
504begin
505  if KeyComp('esp') then Result := tkRegister else
506    Result := tkIdentifier;
507end;
508
509function TSynAASyn.Func43: TtkTokenKind; //alloc /define
510begin
511  if KeyComp('alloc') then Result := tkKey else
512    if KeyComp('define') then Result := tkKey else
513      Result := tkIdentifier;
514end;
515
516function TSynAASyn.Func52: TtkTokenKind; //dealloc
517begin
518  if KeyComp('dealloc') then Result := tkKey else
519    if KeyComp('disable') then Result := tkspace else
520    Result := tkIdentifier;
521end;
522
523function TSynAASyn.Func54: TtkTokenKind; //kalloc
524begin
525  if KeyComp('kalloc') then Result := tkKey else
526    Result := tkIdentifier;
527end;
528
529function TSynAASyn.Func59: TtkTokenKind; //readmem
530begin
531  if KeyComp('readmem') then Result := tkKey else
532    Result := tkIdentifier;
533end;
534
535function TSynAASyn.Func68: TtkTokenKind; //include
536begin
537  if KeyComp('include') then Result := tkKey else
538    Result := tkIdentifier;
539end;
540
541function TSynAASyn.Func82: TtkTokenKind; //include
542begin
543  if KeyComp('assert') then Result := tkKey else
544    Result := tkIdentifier;
545end;
546
547function TSynAASyn.Func92: TtkTokenKind; //globalalloc
548begin
549  if KeyComp('globalalloc') then Result := tkKey else
550    Result := tkIdentifier;
551end;
552
553function TSynAASyn.Func101: TtkTokenKind;
554begin
555  if KeyComp('LoadBinary') then Result := tkKey else
556    if KeyComp('fullaccess') then Result := tkKey else
557      Result := tkIdentifier;
558end;
559
560function TSynAASyn.Func108: TtkTokenKind; //CreateThread
561begin
562  if KeyComp('createthread') then Result := tkKey else
563    Result := tkIdentifier;
564end;
565
566function TSynAASyn.Func117: TtkTokenKind; //loadlibrary
567begin
568  if KeyComp('loadlibrary') then Result := tkKey else
569    Result := tkIdentifier;
570end;
571
572function TSynAASyn.Func187: TtkTokenKind; //registersymbol
573begin
574  if KeyComp('registersymbol') then Result := tkKey else
575    Result := tkIdentifier;
576end;
577
578function TSynAASyn.Func222: TtkTokenKind; //unregistersymbol
579begin
580  if KeyComp('unregistersymbol') then Result := tkKey else
581    Result := tkIdentifier;
582end;
583
584function TSynAASyn.AltFunc: TtkTokenKind;
585begin
586  Result := tkIdentifier
587end;
588
589function TSynAASyn.getfirsttoken(s: string): string;
590var i: integer;
591begin
592  result:=s;
593  for i:=1 to length(s) do
594  begin
595    if (s[i]='(') or (s[i]=' ') or (s[i]=#9) or (s[i]=',') or (s[i]=#10) or (s[i]=#13) then
596    begin
597      result:=copy(s,1,i-1);
598      exit;
599    end;
600  end;
601end;
602
603function TSynAASyn.IdentKind(MayBe: PChar): TtkTokenKind;
604var
605  HashKey: Integer;
606begin
607  fToIdent := MayBe;
608  HashKey := KeyHash(MayBe);
609  if HashKey < 223 then Result := fIdentFuncTable[HashKey] else
610    Result := tkIdentifier;
611
612   
613  if (result=tkIdentifier) then
614  begin
615    if GetOpcodesIndex(getfirsttoken(maybe))<>-1 then
616      result:=tkKey
617    else
618    if isExtraCommand(getfirsttoken(maybe)) then
619      result:=tkKey;
620  end;
621
622
623end;
624
625procedure TSynAASyn.MakeMethodTables;
626var
627  I: Char;
628begin
629  for I := #0 to #255 do
630    case I of
631      #0: fProcTable[I] := NullProc;
632      #10: fProcTable[I] := LFProc;
633      #13: fProcTable[I] := CRProc;
634      #1..#9, #11, #12, #14..#32:
635        fProcTable[I] := SpaceProc;
636      '#': fProcTable[I] := IntegerProc;
637      #39: fProcTable[I] := StringProc;
638      '0'..'9': fProcTable[I] := NumberProc;
639      'A'..'Z', 'a'..'z', '_':
640        fProcTable[I] := IdentProc;
641      '{': fProcTable[I] := BraceOpenProc;
642      '}', '!', '"', '%', '&', '('..'/', ':'..'@', '['..'^', '`', '~':
643        begin
644          case I of
645            '(': fProcTable[I] := RoundOpenProc;
646            '.': fProcTable[I] := PointProc;
647            ';': fProcTable[I] := SemicolonProc;
648            '/': fProcTable[I] := SlashProc;
649            ':', '>': fProcTable[I] := ColonOrGreaterProc;
650            '<': fProcTable[I] := LowerProc;
651            '@': fProcTable[I] := AddressOpProc;
652          else
653            fProcTable[I] := SymbolProc;
654          end;
655        end;
656    else
657      fProcTable[I] := UnknownProc;
658    end;
659end;
660
661constructor TSynAASyn.Create(AOwner: TComponent);
662begin
663  inherited Create(AOwner);
664  fAutoAssemblerVersion := LastAutoAssemblerVersion;
665  fPackageSource := True;
666
667  fAsmAttri := TSynHighlighterAttributes.Create(SYNS_AttrAssembler);
668  AddAttribute(fAsmAttri);
669  fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
670  fCommentAttri.Style:= [fsItalic];
671  fCommentAttri.Foreground:=clBlue;
672
673  AddAttribute(fCommentAttri);
674  fDirecAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor);
675  fDirecAttri.Style:= [fsItalic];
676  AddAttribute(fDirecAttri);
677  fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
678  AddAttribute(fIdentifierAttri);
679  fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
680  fKeyAttri.Style:= [fsBold];
681
682  fRegisterAttri := TSynHighlighterAttributes.Create('Register');
683  fRegisterAttri.Style:= [fsBold];
684  fRegisterAttri.Foreground:=$0080f0;
685
686  AddAttribute(fKeyAttri);
687  fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
688  fNumberAttri.Foreground:=clGreen;
689
690  AddAttribute(fNumberAttri);
691  fFloatAttri := TSynHighlighterAttributes.Create(SYNS_AttrFloat);
692  fFloatAttri.Foreground:=clGreen;
693  AddAttribute(fFloatAttri);
694
695  fHexAttri := TSynHighlighterAttributes.Create(SYNS_AttrHexadecimal);
696  fHexAttri.Foreground:=clGreen;
697  AddAttribute(fHexAttri);
698
699  fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
700  fSpaceAttri.Foreground:=clNavy;
701  AddAttribute(fSpaceAttri);
702
703  fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
704  fStringAttri.Foreground:=clRed;
705
706  AddAttribute(fStringAttri);
707  fCharAttri := TSynHighlighterAttributes.Create(SYNS_AttrCharacter);
708//  fCharAttri.Foreground:=clRed;
709  AddAttribute(fCharAttri);
710  fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
711  AddAttribute(fSymbolAttri);
712  SetAttributesOnChange(DefHighlightChange);
713
714  InitIdent;
715  MakeMethodTables;
716  fRange := rsUnknown;
717  fAsmStart := False;
718  fDefaultFilter := SYNS_FilterPascal;
719end; { Create }
720
721procedure TSynAASyn.SetLine(NewValue: string; LineNumber:Integer);
722begin
723  fLine := PChar(NewValue);
724  Run := 0;
725  fLineNumber := LineNumber;
726  Next;
727end; { SetLine }
728
729procedure TSynAASyn.AddressOpProc;
730begin
731  fTokenID := tkSymbol;
732  inc(Run);
733  if fLine[Run] = '@' then inc(Run);
734end;
735
736procedure TSynAASyn.AsciiCharProc;
737begin
738  fTokenID := tkChar;
739  Inc(Run);
740  while FLine[Run] in ['0'..'9', '$', 'A'..'F', 'a'..'f'] do
741    Inc(Run);
742end;
743
744procedure TSynAASyn.BorProc;
745begin
746  case fLine[Run] of
747     #0: NullProc;
748    #10: LFProc;
749    #13: CRProc;
750  else
751    begin
752      if fRange in [rsDirective, rsDirectiveAsm] then
753        fTokenID := tkDirec
754      else
755        fTokenID := tkComment;
756      repeat
757        if fLine[Run] = '}' then
758        begin
759          Inc(Run);
760          if fRange in [rsBorAsm, rsDirectiveAsm] then
761            fRange := rsAsm
762          else
763            fRange := rsUnKnown;
764          break;
765        end;
766        Inc(Run);
767      until fLine[Run] in [#0, #10, #13];
768    end;
769  end;
770end;
771
772procedure TSynAASyn.BraceOpenProc;
773begin
774 { if (fLine[Run + 1] = '$') then
775  begin
776    if fRange = rsAsm then
777      fRange := rsDirectiveAsm
778    else
779      fRange := rsDirective;
780  end
781  else
782  begin  }
783    if fRange = rsAsm then
784      fRange := rsBorAsm
785    else
786      fRange := rsBor;
787  //end;
788  BorProc;
789end;
790
791procedure TSynAASyn.ColonOrGreaterProc;
792begin
793  fTokenID := tkSymbol;
794  inc(Run);
795  if fLine[Run] = '=' then inc(Run);
796end;
797
798procedure TSynAASyn.CRProc;
799begin
800  fTokenID := tkSpace;
801  inc(Run);
802  if fLine[Run] = #10 then
803    Inc(Run);
804end; { CRProc }
805
806
807procedure TSynAASyn.IdentProc;
808begin
809  fTokenID := IdentKind((fLine + Run));
810  inc(Run, fStringLen);
811  while Identifiers[fLine[Run]] do
812    Inc(Run);
813end; { IdentProc }
814
815
816procedure TSynAASyn.IntegerProc;
817begin
818  inc(Run);
819  fTokenID := tkHex;
820  while FLine[Run] in ['0'..'9', 'A'..'F', 'a'..'f'] do
821    Inc(Run);
822end; { IntegerProc }
823
824
825procedure TSynAASyn.LFProc;
826begin
827  fTokenID := tkSpace;
828  inc(Run);
829end; { LFProc }
830
831
832procedure TSynAASyn.LowerProc;
833begin
834  fTokenID := tkSymbol;
835  inc(Run);
836  if fLine[Run] in ['=', '>'] then
837    Inc(Run);
838end; { LowerProc }
839
840
841procedure TSynAASyn.NullProc;
842begin
843  fTokenID := tkNull;
844end; { NullProc }
845
846procedure TSynAASyn.NumberProc;
847begin
848 { Inc(Run);
849  fTokenID := tkNumber;
850  while FLine[Run] in ['0'..'9', '.', 'e', 'E', '-', '+'] do
851  begin
852    case FLine[Run] of
853      '.':
854        if FLine[Run + 1] = '.' then
855          Break
856        else
857          fTokenID := tkFloat;
858      'e', 'E': fTokenID := tkFloat;
859      '-', '+':
860        begin
861          if fTokenID <> tkFloat then // arithmetic
862            Break;
863          if not (FLine[Run - 1] in ['e', 'E']) then
864            Break; //float, but it ends here
865        end;
866    end;
867    Inc(Run);
868  end;   }
869    fTokenID := IdentKind((fLine + Run));
870
871  if fTokenID=tkIdentifier then
872  begin
873    inc(Run);
874    fTokenID := tkNumber;
875    while FLine[Run] in ['0'..'9', '.', 'a'..'f' , 'A'..'F'] do
876    begin
877      {case FLine[Run] of
878        '.':
879          if FLine[Run + 1] = '.' then break;
880      end;   }
881      inc(Run);
882    end;
883
884    if ((FLine[Run]>'G') and (FLine[Run]<='Z')) or ((FLine[Run]>='g') and (FLine[Run]<='z')) then
885      fTokenID:=tkIdentifier;
886  end
887  else
888  begin
889    inc(Run, fStringLen);
890    while Identifiers[fLine[Run]] do inc(Run);
891  end;
892end; { NumberProc }
893
894procedure TSynAASyn.PointProc;
895begin
896  fTokenID := tkSymbol;
897  inc(Run);
898  if fLine[Run] in ['.', ')'] then
899    Inc(Run);
900end; { PointProc }
901
902procedure TSynAASyn.AnsiProc;
903begin
904{  case fLine[Run] of
905     #0: NullProc;
906    #10: LFProc;
907    #13: CRProc;
908  else
909    fTokenID := tkComment;
910    repeat
911      if (fLine[Run] = '*') and (fLine[Run + 1] = ')') then begin
912        Inc(Run, 2);
913        if fRange = rsAnsiAsm then
914          fRange := rsAsm
915        else
916          fRange := rsUnKnown;
917        break;
918      end;
919      Inc(Run);
920    until fLine[Run] in [#0, #10, #13];
921  end;   }
922  case fLine[Run] of
923     #0: NullProc;
924    #10: LFProc;
925    #13: CRProc;
926  else
927    fTokenID := tkComment;
928    repeat
929      if (fLine[Run] = '*') and (fLine[Run + 1] = '/') then begin
930        Inc(Run, 2);
931        if fRange = rsAnsiAsm then
932          fRange := rsAsm
933        else
934          fRange := rsUnKnown;
935        break;
936      end;
937      Inc(Run);
938    until fLine[Run] in [#0, #10, #13];
939  end
940end;
941
942procedure TSynAASyn.RoundOpenProc;
943begin
944  Inc(Run);
945  case fLine[Run] of
946  {  '*':
947      begin
948        Inc(Run);
949        if fRange = rsAsm then
950          fRange := rsAnsiAsm
951        else
952          fRange := rsAnsi;
953        fTokenID := tkComment;
954        if not (fLine[Run] in [#0, #10, #13]) then
955          AnsiProc;
956      end; }
957    '.':
958      begin
959        inc(Run);
960        fTokenID := tkSymbol;
961      end;
962  else
963    fTokenID := tkSymbol;
964  end;
965end;
966
967procedure TSynAASyn.SemicolonProc;
968begin
969  Inc(Run);
970  fTokenID := tkSymbol;
971  if fRange in [rsProperty, rsExports] then
972    fRange := rsUnknown;
973end;
974
975procedure TSynAASyn.SlashProc;
976begin
977 { Inc(Run);
978  if (fLine[Run] = '/') and (fAutoAssemblerVersion > dvAutoAssembler1) then
979  begin
980    fTokenID := tkComment;
981    repeat
982      Inc(Run);
983    until fLine[Run] in [#0, #10, #13];
984  end
985  else if (fLine[Run] = '*') then
986  begin
987    fTokenID := tkComment;
988    repeat
989      Inc(Run);
990     
991    until fLine[Run] in [#0];
992  end else fTokenID := tkSymbol;  }
993
994  Inc(Run);
995  if fLine[Run] = '/' then
996  begin
997    fTokenID := tkComment;
998    repeat
999      Inc(Run);
1000    until fLine[Run] in [#0, #10, #13];
1001  end
1002  else
1003  if fline[run] = '*' then
1004  begin
1005      begin
1006        Inc(Run);
1007        if fRange = rsAsm then
1008          fRange := rsAnsiAsm
1009        else
1010          fRange := rsAnsi;
1011        fTokenID := tkComment;
1012        if not (fLine[Run] in [#0, #10, #13]) then
1013          AnsiProc;
1014      end;
1015  end 
1016  else fTokenID := tkSymbol; 
1017
1018end;
1019
1020procedure TSynAASyn.SpaceProc;
1021begin
1022  inc(Run);
1023  fTokenID := tkSpace;
1024  while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
1025end;
1026
1027procedure TSynAASyn.StringProc;
1028begin
1029  fTokenID := tkString;
1030  Inc(Run);
1031  while not (fLine[Run] in [#0, #10, #13]) do begin
1032    if fLine[Run] = #39 then begin
1033      Inc(Run);
1034      if fLine[Run] <> #39 then
1035        break;
1036    end;
1037    Inc(Run);
1038  end;
1039end;
1040
1041procedure TSynAASyn.SymbolProc;
1042begin
1043  inc(Run);
1044  fTokenID := tkSymbol;
1045end;
1046
1047procedure TSynAASyn.UnknownProc;
1048begin
1049{$IFDEF SYN_MBCSSUPPORT}
1050  if FLine[Run] in LeadBytes then
1051    Inc(Run, 2)
1052  else
1053{$ENDIF}
1054  inc(Run);
1055  fTokenID := tkUnknown;
1056end;
1057
1058procedure TSynAASyn.Next;
1059begin
1060  fAsmStart := False;
1061  fTokenPos := Run;
1062  case fRange of
1063    rsAnsi, rsAnsiAsm:
1064      AnsiProc;
1065    rsBor, rsBorAsm, rsDirective, rsDirectiveAsm:
1066      BorProc;
1067  else
1068    fProcTable[fLine[Run]];
1069  end;
1070end;
1071
1072function TSynAASyn.GetDefaultAttribute(Index: integer):
1073  TSynHighlighterAttributes;
1074begin
1075  case Index of
1076    SYN_ATTR_COMMENT: Result := fCommentAttri;
1077    SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;
1078    SYN_ATTR_KEYWORD: Result := fKeyAttri;
1079    SYN_ATTR_STRING: Result := fStringAttri;
1080    SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
1081    SYN_ATTR_SYMBOL: Result := fSymbolAttri;
1082  else
1083    Result := nil;
1084  end;
1085end;
1086
1087function TSynAASyn.GetEol: Boolean;
1088begin
1089  Result := fTokenID = tkNull;
1090end;
1091
1092function TSynAASyn.GetToken: string;
1093var
1094  Len: LongInt;
1095begin
1096  Len := Run - fTokenPos;
1097  SetString(Result, (FLine + fTokenPos), Len);
1098end;
1099
1100function TSynAASyn.GetTokenID: TtkTokenKind;
1101begin
1102  if not fAsmStart and (fRange = rsAsm)
1103    and not (fTokenId in [tkNull, tkComment, tkDirec, tkSpace])
1104  then
1105    Result := tkAsm
1106  else
1107    Result := fTokenId;
1108end;
1109
1110function TSynAASyn.GetTokenAttribute: TSynHighlighterAttributes;
1111begin
1112  case GetTokenID of
1113    tkAsm: Result := fAsmAttri;
1114    tkComment: Result := fCommentAttri;
1115    tkDirec: Result := fDirecAttri;
1116    tkIdentifier: Result := fIdentifierAttri;
1117    tkKey: Result := fKeyAttri;
1118    tkRegister: Result := fRegisterAttri;
1119    tkNumber: Result := fNumberAttri;
1120    tkFloat: Result := fFloatAttri;
1121    tkHex: Result := fHexAttri;
1122    tkSpace: Result := fSpaceAttri;
1123    tkString: Result := fStringAttri;
1124    tkChar: Result := fCharAttri;
1125    tkSymbol: Result := fSymbolAttri;
1126    tkUnknown: Result := fSymbolAttri;
1127  else
1128    Result := nil;
1129  end;
1130end;
1131
1132function TSynAASyn.GetTokenKind: integer;
1133begin
1134  Result := Ord(GetTokenID);
1135end;
1136
1137function TSynAASyn.GetTokenPos: Integer;
1138begin
1139  Result := fTokenPos;
1140end;
1141
1142function TSynAASyn.GetRange: Pointer;
1143begin
1144  Result := Pointer(fRange);
1145end;
1146
1147procedure TSynAASyn.SetRange(Value: Pointer);
1148begin
1149  fRange := TRangeState(Value);
1150end;
1151
1152procedure TSynAASyn.ResetRange;
1153begin
1154  fRange:= rsUnknown;
1155end;
1156
1157function TSynAASyn.GetIdentChars: TSynIdentChars;
1158begin
1159  Result := TSynValidStringChars;
1160end;
1161
1162function TSynAASyn.GetSampleSource: string;
1163begin
1164  Result :=  'NYI'#13#10;
1165end; { GetSampleSource }
1166
1167
1168class function TSynAASyn.GetLanguageName: string;
1169begin
1170  Result := SYNS_LangPascal;
1171end;
1172
1173class function TSynAASyn.GetCapabilities: TSynHighlighterCapabilities;
1174begin
1175  Result := inherited GetCapabilities + [hcUserSettings];
1176end;
1177
1178function TSynAASyn.IsFilterStored: boolean;
1179begin
1180  Result := fDefaultFilter <> SYNS_FilterPascal;
1181end;
1182
1183procedure TSynAASyn.SetAutoAssemblerVersion(const Value: TAutoAssemblerVersion);
1184begin
1185  if fAutoAssemblerVersion <> Value then
1186  begin
1187    fAutoAssemblerVersion := Value;
1188    if (fAutoAssemblerVersion < dvAutoAssembler3) and fPackageSource then
1189      fPackageSource := False;
1190    DefHighlightChange( Self );
1191  end;
1192end;
1193
1194
1195procedure TSynAASyn.SetPackageSource(const Value: Boolean);
1196begin
1197  if fPackageSource <> Value then
1198  begin
1199    fPackageSource := Value;
1200    if fPackageSource and (fAutoAssemblerVersion < dvAutoAssembler3) then
1201      fAutoAssemblerVersion := dvAutoAssembler3;
1202    DefHighlightChange( Self );
1203  end;
1204end;
1205
1206
1207initialization
1208  MakeIdentTable;
1209{$IFNDEF SYN_CPPB_1}
1210  RegisterPlaceableHighlighter(TSynAASyn);
1211{$ENDIF}
1212end.
Note: See TracBrowser for help on using the browser.