-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSynD16Highlighter.pas
1448 lines (1320 loc) · 43.5 KB
/
SynD16Highlighter.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{------------------------------------------------------------------------------
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.
This File is based on the SynHighlighterPas.pas and adds detailed asm highlightning
and is customized to fit better for the D16Pascal language(just a few minor changes)
Known Issues:
-------------------------------------------------------------------------------}
{
@abstract(Provides a Pascal/Delphi syntax highlighter for SynEdit)
@author(Martin Waldenburg, Alexander Benikowski)
@created(2013, based on the SynHighlighterPas from 2004-03-19)
@lastmod(2013-04-23)
The SynD16Highlighter unit provides SynEdit with a Object Pascal/D16Pascal syntax highlighter.
Two extra properties included (DelphiVersion, PackageSource):
DelphiVersion - Allows you to enable/disable the highlighting of various
language enhancements added in the different Delphi versions.
PackageSource - Allows you to enable/disable the highlighting of package keywords
}
{$IFNDEF QSYNHIGHLIGHTERPAS}
unit SynD16Highlighter;
{$ENDIF}
{$I SynEdit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
QSynUnicode,
{$ELSE}
Windows,
Graphics,
SynEditTypes,
SynEditHighlighter,
SynUnicode,
{$ENDIF}
Generics.Collections,
SysUtils,
Classes;
type
TtkTokenKind = (tkAsm, tkComment, tkIdentifier, tkKey, tkNull, tkNumber,
tkSpace, tkString, tkSymbol, tkUnknown, tkFloat, tkHex, tkDirec, tkChar);
TRangeState = (rsANil, rsAnsi, rsAnsiAsm, rsAsm, rsBor, rsBorAsm, rsProperty,
rsExports, rsDirective, rsDirectiveAsm, rsUnKnown);
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function (Index: Integer): TtkTokenKind of object;
TDelphiVersion = (dvDelphi1, dvDelphi2, dvDelphi3, dvDelphi4, dvDelphi5,
dvDelphi6, dvDelphi7, dvDelphi8, dvDelphi2005);
const
LastDelphiVersion = dvDelphi2005;
BDSVersionPrefix = 'BDS';
CTableDASMStart = 389;
type
TSynD16Syn = class(TSynCustomHighlighter)
private
fAsmStart: Boolean;
fRange: TRangeState;
fIdentFuncTable: array[0..426] of TIdentFuncTableFunc;
fTokenID: TtkTokenKind;
fStringAttri: TSynHighlighterAttributes;
fCharAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fFloatAttri: TSynHighlighterAttributes;
fHexAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fAsmAttri: TSynHighlighterAttributes;
fCommentAttri: TSynHighlighterAttributes;
fDirecAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fDelphiVersion: TDelphiVersion;
fPackageSource: Boolean;
FD16Keywords: TDictionary<string, Integer>;
FDASMKeywords: TDictionary<string, Integer>;
function AltFunc(Index: Integer): TtkTokenKind;
function KeyWordFunc(Index: Integer): TtkTokenKind;
function FuncAsm(Index: Integer): TtkTokenKind;
function FuncAutomated(Index: Integer): TtkTokenKind;
function FuncCdecl(Index: Integer): TtkTokenKind;
function FuncContains(Index: Integer): TtkTokenKind;
function FuncDeprecated(Index: Integer): TtkTokenKind;
function FuncDispid(Index: Integer): TtkTokenKind;
function FuncDispinterface(Index: Integer): TtkTokenKind;
function FuncEnd(Index: Integer): TtkTokenKind;
function FuncExports(Index: Integer): TtkTokenKind;
function FuncFinal(Index: Integer): TtkTokenKind;
function FuncFinalization(Index: Integer): TtkTokenKind;
function FuncHelper(Index: Integer): TtkTokenKind;
function FuncImplements(Index: Integer): TtkTokenKind;
function FuncIndex(Index: Integer): TtkTokenKind;
function FuncName(Index: Integer): TtkTokenKind;
function FuncNodefault(Index: Integer): TtkTokenKind;
function FuncOperator(Index: Integer): TtkTokenKind;
function FuncOverload(Index: Integer): TtkTokenKind;
function FuncPackage(Index: Integer): TtkTokenKind;
function FuncPlatform(Index: Integer): TtkTokenKind;
function FuncProperty(Index: Integer): TtkTokenKind;
function FuncRead(Index: Integer): TtkTokenKind;
function FuncReadonly(Index: Integer): TtkTokenKind;
function FuncReintroduce(Index: Integer): TtkTokenKind;
function FuncRequires(Index: Integer): TtkTokenKind;
function FuncResourcestring(Index: Integer): TtkTokenKind;
function FuncSafecall(Index: Integer): TtkTokenKind;
function FuncSealed(Index: Integer): TtkTokenKind;
function FuncStdcall(Index: Integer): TtkTokenKind;
function FuncStored(Index: Integer): TtkTokenKind;
function FuncStringresource(Index: Integer): TtkTokenKind;
function FuncThreadvar(Index: Integer): TtkTokenKind;
function FuncWrite(Index: Integer): TtkTokenKind;
function FuncWriteonly(Index: Integer): TtkTokenKind;
function HashKey(Str: PWideChar): Cardinal;
function IdentKind(MayBe: PWideChar): TtkTokenKind;
procedure InitIdent;
procedure AddressOpProc;
procedure AsciiCharProc;
procedure AnsiProc;
procedure BorProc;
procedure BraceOpenProc;
procedure ColonOrGreaterProc;
procedure CRProc;
procedure IdentProc;
procedure IntegerProc;
procedure LFProc;
procedure LowerProc;
procedure NullProc;
procedure NumberProc;
procedure PointProc;
procedure RoundOpenProc;
procedure SemicolonProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure SymbolProc;
procedure DASMStringProc;
procedure UnknownProc;
procedure SetDelphiVersion(const Value: TDelphiVersion);
procedure SetPackageSource(const Value: Boolean);
procedure InitKeyWords();
protected
function GetSampleSource: UnicodeString; override;
function IsFilterStored: Boolean; override;
public
class function GetCapabilities: TSynHighlighterCapabilities; override;
class function GetLanguageName: string; override;
class function GetFriendlyLanguageName: UnicodeString; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
function GetDefaultAttribute(Index: Integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetRange: Pointer; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenID: TtkTokenKind;
function GetTokenKind: Integer; override;
procedure Next; override;
procedure ResetRange; override;
procedure SetRange(Value: Pointer); override;
function UseUserSettings(VersionIndex: Integer): Boolean; override;
procedure EnumUserSettings(DelphiVersions: TStrings); override;
published
property AsmAttri: TSynHighlighterAttributes read fAsmAttri write fAsmAttri;
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property DirectiveAttri: TSynHighlighterAttributes read fDirecAttri
write fDirecAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property FloatAttri: TSynHighlighterAttributes read fFloatAttri
write fFloatAttri;
property HexAttri: TSynHighlighterAttributes read fHexAttri
write fHexAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
property CharAttri: TSynHighlighterAttributes read fCharAttri
write fCharAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
property DelphiVersion: TDelphiVersion read fDelphiVersion write SetDelphiVersion
default LastDelphiVersion;
property PackageSource: Boolean read fPackageSource write SetPackageSource default True;
end;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst;
{$ELSE}
SynEditStrConst;
{$ENDIF}
const
// if the language is case-insensitive keywords *must* be in lowercase
{base KeyWords 0..110, DASM related keywords 111..end}
KeyWords: array[0..148] of UnicodeString = (
'absolute', 'abstract', 'and', 'array', 'as', 'asm', 'assembler',
'automated', 'begin', 'case', 'cdecl', 'class', 'const', 'constructor',
'contains', 'default', 'deprecated', 'destructor', 'dispid',
'dispinterface', 'div', 'do', 'downto', 'dynamic', 'else', 'end', 'except',
'export', 'exports', 'external', 'far', 'file', 'final', 'finalization',
'finally', 'for', 'forward', 'function', 'goto', 'helper', 'if',
'implementation', 'implements', 'in', 'index', 'inherited',
'initialization', 'inline', 'interface', 'is', 'label', 'library',
'message', 'mod', 'name', 'near', 'nil', 'nodefault', 'not', 'object', 'of',
'on', 'operator', 'or', 'out', 'overload', 'override', 'package', 'packed',
'pascal', 'platform', 'private', 'procedure', 'program', 'property',
'protected', 'public', 'published', 'raise', 'read', 'readonly', 'record',
'register', 'reintroduce', 'repeat', 'requires', 'resourcestring',
'safecall', 'sealed', 'set', 'shl', 'shr', 'stdcall', 'stored', 'string',
'stringresource', 'then', 'threadvar', 'to', 'try', 'type', 'unit', 'until',
'uses', 'var', 'virtual', 'while', 'with', 'write', 'writeonly', 'xor'
{DASM related keywords, only active in ASM block, however 'end' is required to trigger asm end},
'end', 'set', 'add', 'sub', 'mul', 'mli', 'div', 'dvi', 'mod', 'mdi', 'and', 'bor', 'xor',
'shr', 'asr', 'shl', 'ifb', 'ifc', 'ife', 'ifn', 'ifg', 'ifa', 'ifl', 'ifu', 'adx',
'sbx', 'sti', 'std', 'jsr', 'int', 'iag', 'ias', 'rfi', 'iaq', 'hwn', 'hwq', 'hwi', 'dat'
);
{base indices 0..388, DASM indices 389..end}
KeyIndices: array[0..426] of Integer = (
-1, -1, -1, 105, -1, 51, -1, 108, -1, -1, -1, -1, -1, 75, -1, -1, 46, -1,
-1, 103, -1, -1, -1, -1, 55, -1, -1, -1, -1, 76, -1, -1, 96, 14, -1, 31, 3,
102, -1, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 78, -1, -1, 25, -1,
-1, 56, 65, 95, -1, -1, -1, 34, -1, 85, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 22, -1, -1, -1, -1, -1, -1, 80, -1, -1, -1, -1, 50, -1, -1, 109, 98, -1,
86, -1, 13, -1, -1, -1, 107, -1, -1, 60, -1, 0, 64, -1, -1, -1, -1, 8, 10,
-1, -1, -1, 67, -1, -1, -1, 74, -1, 17, -1, 73, 69, -1, 68, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 16, -1, -1, 23, 39, -1, 35, 30, -1, -1, -1, 70, -1, 37,
-1, -1, 89, 71, 84, 72, -1, 29, 40, -1, -1, -1, 32, -1, -1, -1, 94, -1, -1,
87, -1, -1, -1, -1, -1, -1, 77, -1, -1, -1, -1, -1, -1, 11, 57, 41, 6, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, 97, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 44, 12, -1, -1, 101, -1, 58, -1, -1, -1, 99, -1, -1,
-1, -1, 53, 20, -1, -1, -1, 36, -1, -1, 63, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 45, -1, -1, -1, -1, 27, -1, -1, -1, -1, -1, 59,
-1, 110, -1, 15, -1, 52, -1, -1, -1, -1, 5, 48, -1, -1, -1, 81, -1, 28, -1,
-1, -1, 2, -1, 1, -1, 106, -1, -1, -1, -1, 90, -1, 83, -1, -1, -1, -1, -1,
79, -1, -1, 33, 62, -1, -1, -1, -1, -1, -1, 4, -1, -1, -1, -1, -1, -1, 88,
61, 54, -1, 42, -1, -1, -1, 66, -1, -1, -1, 92, 100, -1, -1, -1, -1, -1, 18,
-1, -1, 26, 47, 38, -1, -1, 93, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
9, -1, 91, -1, -1, -1, -1, -1, -1, 49, -1, 21, -1, -1, -1, -1, -1, -1, 43,
-1, 82, -1, 19, 104, -1, -1, -1, -1, -1
{DASM related indices},
111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148
);
{$Q-}
function TSynD16Syn.HashKey(Str: PWideChar): Cardinal;
var
LKey: string;
LValue: Integer;
begin
Result := 0;
LKey := '';
while IsIdentChar(Str^) do
begin
LKey := LKey + Str^;
//Result := Result * 812 + Ord(Str^) * 76;
inc(Str);
end;
//Result := Result mod High(fIdentFuncTable);// 389;//Length(fIdentFuncTable);//389;
if (fRange = rsAsm)then
begin
if FDASMKeywords.TryGetValue(LKey, LValue) then
begin
Result := LValue;
end;
end
else
begin
if FD16Keywords.TryGetValue(LKey, LValue) then
begin
Result := LValue;
end;
end;
fStringLen := Str - fToIdent;
end;
{$Q+}
function TSynD16Syn.IdentKind(MayBe: PWideChar): TtkTokenKind;
var
Key: Cardinal;
begin
fToIdent := MayBe;
Key := HashKey(MayBe);
if Key <= High(fIdentFuncTable) then
Result := fIdentFuncTable[Key](KeyIndices[Key])
else
Result := tkIdentifier;
end;
procedure TSynD16Syn.InitIdent;
var
i: Integer;
begin
for i := Low(fIdentFuncTable) to High(fIdentFuncTable) do
if KeyIndices[i] = -1 then
fIdentFuncTable[i] := AltFunc;
//these functions are active during normal D16pascal
fIdentFuncTable[275] := FuncAsm;
fIdentFuncTable[41] := FuncAutomated;
fIdentFuncTable[112] := FuncCdecl;
fIdentFuncTable[33] := FuncContains;
fIdentFuncTable[137] := FuncDeprecated;
fIdentFuncTable[340] := FuncDispid;
fIdentFuncTable[382] := FuncDispinterface;
fIdentFuncTable[54] := FuncEnd;
fIdentFuncTable[282] := FuncExports;
fIdentFuncTable[163] := FuncFinal;
fIdentFuncTable[306] := FuncFinalization;
fIdentFuncTable[141] := FuncHelper;
fIdentFuncTable[325] := FuncImplements;
fIdentFuncTable[214] := FuncIndex;
fIdentFuncTable[323] := FuncName;
fIdentFuncTable[185] := FuncNodefault;
fIdentFuncTable[307] := FuncOperator;
fIdentFuncTable[58] := FuncOverload;
fIdentFuncTable[116] := FuncPackage;
fIdentFuncTable[148] := FuncPlatform;
fIdentFuncTable[120] := FuncProperty;
fIdentFuncTable[303] := FuncRead;
fIdentFuncTable[83] := FuncReadonly;
fIdentFuncTable[297] := FuncReintroduce;
fIdentFuncTable[65] := FuncRequires;
fIdentFuncTable[94] := FuncResourcestring;
fIdentFuncTable[170] := FuncSafecall;
fIdentFuncTable[321] := FuncSealed;
fIdentFuncTable[333] := FuncStdcall;
fIdentFuncTable[348] := FuncStored;
fIdentFuncTable[59] := FuncStringresource;
fIdentFuncTable[204] := FuncThreadvar;
fIdentFuncTable[7] := FuncWrite;
fIdentFuncTable[91] := FuncWriteonly;
//theses functions are active in ASM blocks ONLY
fIdentFuncTable[CTableDASMStart] := FuncEnd;
for i := Low(fIdentFuncTable) to High(fIdentFuncTable) do
if @fIdentFuncTable[i] = nil then
fIdentFuncTable[i] := KeyWordFunc;
end;
procedure TSynD16Syn.InitKeyWords;
var
i: Integer;
LIndex: Integer;
begin
for i := Low(KeyIndices) to CTableDASMStart -1 do
begin
if KeyIndices[i] > -1 then
begin
FD16Keywords.Add(KeyWords[KeyIndices[i]], i);
end;
end;
for i := CTableDASMStart to High(KeyIndices) do
begin
FDASMKeywords.Add(KeyWords[KeyIndices[i]], i);
end;
end;
function TSynD16Syn.AltFunc(Index: Integer): TtkTokenKind;
begin
Result := tkIdentifier
end;
function TSynD16Syn.KeyWordFunc(Index: Integer): TtkTokenKind;
begin
if IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier
end;
function TSynD16Syn.FuncAsm(Index: Integer): TtkTokenKind;
begin
if IsCurrentToken(KeyWords[Index]) then
begin
Result := tkKey;
fRange := rsAsm;
fAsmStart := True;
end
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncAutomated(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncCdecl(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi2) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncContains(Index: Integer): TtkTokenKind;
begin
if PackageSource and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncDeprecated(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi6) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncDispid(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncDispinterface(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncEnd(Index: Integer): TtkTokenKind;
begin
if IsCurrentToken(KeyWords[Index]) then
begin
Result := tkKey;
fRange := rsUnknown;
end
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncExports(Index: Integer): TtkTokenKind;
begin
if IsCurrentToken(KeyWords[Index]) then
begin
Result := tkKey;
fRange := rsExports;
end
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncFinal(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi8) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncFinalization(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi2) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncHelper(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi8) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncImplements(Index: Integer): TtkTokenKind;
begin
if (fRange = rsProperty) and (DelphiVersion >= dvDelphi4) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncIndex(Index: Integer): TtkTokenKind;
begin
if (fRange in [rsProperty, rsExports]) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncName(Index: Integer): TtkTokenKind;
begin
if (fRange = rsExports) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncNodefault(Index: Integer): TtkTokenKind;
begin
if (fRange = rsProperty) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncOperator(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi8) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncOverload(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi4) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncPackage(Index: Integer): TtkTokenKind;
begin
if PackageSource and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncPlatform(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi6) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncProperty(Index: Integer): TtkTokenKind;
begin
if IsCurrentToken(KeyWords[Index]) then
begin
Result := tkKey;
fRange := rsProperty;
end
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncRead(Index: Integer): TtkTokenKind;
begin
if (fRange = rsProperty) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncReadonly(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and (fRange = rsProperty) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncReintroduce(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi4) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncRequires(Index: Integer): TtkTokenKind;
begin
if PackageSource and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncResourcestring(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncSafecall(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncSealed(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi8) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncStdcall(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi2) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncStored(Index: Integer): TtkTokenKind;
begin
if (fRange = rsProperty) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncStringresource(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncThreadvar(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncWrite(Index: Integer): TtkTokenKind;
begin
if (fRange = rsProperty) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
function TSynD16Syn.FuncWriteonly(Index: Integer): TtkTokenKind;
begin
if (DelphiVersion >= dvDelphi3) and (fRange = rsProperty) and IsCurrentToken(KeyWords[Index]) then
Result := tkKey
else
Result := tkIdentifier;
end;
constructor TSynD16Syn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FD16Keywords := TDictionary<string, Integer>.Create();
FDASMKeywords := TDictionary<string, Integer>.Create();
InitKeyWords();
fCaseSensitive := False;
fDelphiVersion := LastDelphiVersion;
fPackageSource := True;
fAsmAttri := TSynHighlighterAttributes.Create(SYNS_AttrAssembler, SYNS_FriendlyAttrAssembler);
AddAttribute(fAsmAttri);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment, SYNS_FriendlyAttrComment);
fCommentAttri.Style:= [fsItalic];
AddAttribute(fCommentAttri);
fDirecAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor, SYNS_FriendlyAttrPreprocessor);
fDirecAttri.Style:= [fsItalic];
AddAttribute(fDirecAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier, SYNS_FriendlyAttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord, SYNS_FriendlyAttrReservedWord);
fKeyAttri.Style:= [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber, SYNS_FriendlyAttrNumber);
AddAttribute(fNumberAttri);
fFloatAttri := TSynHighlighterAttributes.Create(SYNS_AttrFloat, SYNS_FriendlyAttrFloat);
AddAttribute(fFloatAttri);
fHexAttri := TSynHighlighterAttributes.Create(SYNS_AttrHexadecimal, SYNS_FriendlyAttrHexadecimal);
AddAttribute(fHexAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace, SYNS_FriendlyAttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString, SYNS_FriendlyAttrString);
AddAttribute(fStringAttri);
fCharAttri := TSynHighlighterAttributes.Create(SYNS_AttrCharacter, SYNS_FriendlyAttrCharacter);
AddAttribute(fCharAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol, SYNS_FriendlyAttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange(DefHighlightChange);
InitIdent;
fRange := rsUnknown;
fAsmStart := False;
fDefaultFilter := SYNS_FilterPascal;
//init colors
AsmAttri.Foreground := clRed;
AsmAttri.Style := [fsBold];
KeyAttri.Foreground := clNavy;
CommentAttri.Foreground := clGreen;
StringAttri.Foreground := clBlue;
NumberAttri.Foreground := clBlue;
HexAttri.Foreground := clBlue;
end;
procedure TSynD16Syn.AddressOpProc;
begin
fTokenID := tkSymbol;
inc(Run);
if fLine[Run] = '@' then inc(Run);
end;
procedure TSynD16Syn.AsciiCharProc;
function IsAsciiChar: Boolean;
begin
case fLine[Run] of
'0'..'9', '$', 'A'..'F', 'a'..'f':
Result := True;
else
Result := False;
end;
end;
begin
fTokenID := tkChar;
Inc(Run);
while IsAsciiChar do
Inc(Run);
end;
procedure TSynD16Syn.BorProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
begin
if fRange in [rsDirective, rsDirectiveAsm] then
fTokenID := tkDirec
else
fTokenID := tkComment;
repeat
if fLine[Run] = '}' then
begin
Inc(Run);
if fRange in [rsBorAsm, rsDirectiveAsm] then
fRange := rsAsm
else
fRange := rsUnKnown;
break;
end;
Inc(Run);
until IsLineEnd(Run);
end;
end;
end;
procedure TSynD16Syn.BraceOpenProc;
begin
if (fLine[Run + 1] = '$') then
begin
if fRange = rsAsm then
fRange := rsDirectiveAsm
else
fRange := rsDirective;
end
else
begin
if fRange = rsAsm then
fRange := rsBorAsm
else
fRange := rsBor;
end;
BorProc;
end;
procedure TSynD16Syn.ColonOrGreaterProc;
begin
fTokenID := tkSymbol;
inc(Run);
if fLine[Run] = '=' then inc(Run);
end;
procedure TSynD16Syn.CRProc;
begin
fTokenID := tkSpace;
inc(Run);
if fLine[Run] = #10 then
Inc(Run);
end;
procedure TSynD16Syn.DASMStringProc;
begin
fTokenID := tkString;
Inc(Run);
while not IsLineEnd(Run) do
begin
if fLine[Run] = '"' then begin
Inc(Run);
if fLine[Run] <> '"' then
break;
end;
Inc(Run);
end;
end;
destructor TSynD16Syn.Destroy;
begin
FD16Keywords.Free;
FDASMKeywords.Free;
inherited;
end;
procedure TSynD16Syn.IdentProc;
begin
fTokenID := IdentKind(fLine + Run);
inc(Run, fStringLen);
while IsIdentChar(fLine[Run]) do
Inc(Run);
end;
procedure TSynD16Syn.IntegerProc;
function IsIntegerChar: Boolean;
begin
case fLine[Run] of
'0'..'9', 'A'..'F', 'a'..'f':
Result := True;
else
Result := False;
end;
end;
begin
inc(Run);
fTokenID := tkHex;
while IsIntegerChar do
Inc(Run);
end;
procedure TSynD16Syn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynD16Syn.LowerProc;
begin
fTokenID := tkSymbol;
inc(Run);
if (fLine[Run] = '=') or (fLine[Run] = '>') then
Inc(Run);
end;
procedure TSynD16Syn.NullProc;
begin
fTokenID := tkNull;
inc(Run);
end;
procedure TSynD16Syn.NumberProc;
function IsNumberChar: Boolean;
begin
case fLine[Run] of
'0'..'9', '.', 'e', 'E', '-', '+':
Result := True;
else
Result := False;
end;
end;
begin
Inc(Run);
if (fLine[Run-1] = '0') and (fLine[Run] = 'x') then
begin
IntegerProc();//this allows HexValues with the prefix 0x instead of just $
Exit;
end;
fTokenID := tkNumber;
while IsNumberChar do
begin
case fLine[Run] of
'.':
if fLine[Run + 1] = '.' then
Break
else
fTokenID := tkFloat;
'e', 'E': fTokenID := tkFloat;
'-', '+':
begin
if fTokenID <> tkFloat then // arithmetic
Break;
if (FLine[Run - 1] <> 'e') and (FLine[Run - 1] <> 'E') then
Break; //float, but it ends here
end;
end;
Inc(Run);
end;
end;
procedure TSynD16Syn.PointProc;
begin
fTokenID := tkSymbol;
inc(Run);
if (fLine[Run] = '.') or (fLine[Run - 1] = ')') then
Inc(Run);
end;
procedure TSynD16Syn.AnsiProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if (fLine[Run] = '*') and (fLine[Run + 1] = ')') then begin
Inc(Run, 2);
if fRange = rsAnsiAsm then
fRange := rsAsm
else
fRange := rsUnKnown;
break;
end;
Inc(Run);
until IsLineEnd(Run);
end;
end;
procedure TSynD16Syn.RoundOpenProc;
begin
Inc(Run);
case fLine[Run] of
'*':
begin
Inc(Run);
if fRange = rsAsm then
fRange := rsAnsiAsm
else
fRange := rsAnsi;
fTokenID := tkComment;
if not IsLineEnd(Run) then
AnsiProc;
end;
'.':
begin
inc(Run);
fTokenID := tkSymbol;
end;
else
fTokenID := tkSymbol;
end;
end;
procedure TSynD16Syn.SemicolonProc;
begin
if fRange = rsAsm then
begin
fTokenID := tkComment;
repeat
Inc(Run)
until IsLineEnd(Run);
end
else