-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModHighlighter.bas
More file actions
1000 lines (826 loc) · 42.9 KB
/
Copy pathModHighlighter.bas
File metadata and controls
1000 lines (826 loc) · 42.9 KB
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
Attribute VB_Name = "ModHighlighter"
'Author: David Zimmer <dzzie@yahoo.com>
'AI: Claude.ai
'Site: http://sandsprite.com
'License: MIT
'---------------------------------------------------
'NOTE: if a color is off it may be because vb6 ide is truncating it to an int and it requires the high bytes to be 0
'i had to declare one as Const CLR_DARK_GREEN As Long = &H008000&
'we may have to fix more bleh
Option Explicit
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'=========================================================================
' ModHighlighter - Professional syntax highlighting presets for SciWrapper
' Adapted to work with modular API architecture
'=========================================================================
' Scintilla CPP lexer style constants
Private Const SCE_C_DEFAULT = 0
Private Const SCE_C_COMMENT = 1
Private Const SCE_C_COMMENTLINE = 2
Private Const SCE_C_COMMENTDOC = 3
Private Const SCE_C_NUMBER = 4
Private Const SCE_C_WORD = 5
Private Const SCE_C_STRING = 6
Private Const SCE_C_CHARACTER = 7
Private Const SCE_C_UUID = 8
Private Const SCE_C_PREPROCESSOR = 9
Private Const SCE_C_OPERATOR = 10
Private Const SCE_C_IDENTIFIER = 11
Private Const SCE_C_STRINGEOL = 12
Private Const SCE_C_VERBATIM = 13
Private Const SCE_C_REGEX = 14
Private Const SCE_C_COMMENTLINEDOC = 15
Private Const SCE_C_WORD2 = 16
Private Const SCE_C_COMMENTDOCKEYWORD = 17
Private Const SCE_C_COMMENTDOCKEYWORDERROR = 18
Private Const SCE_C_GLOBALCLASS = 19
Global Const BREAKPOINT_MARKER As Long = 1
Global Const BREAKPOINT_MASK As Long = 2
Global Const LANG_US = &H409
Enum shellOpenState
so_Hidden = 0
so_Min = 2
so_Max = 3
so_Norm = 4
End Enum
Public Function ShellExec(path As String, _
Optional ByVal action As String = "Open", _
Optional ByVal Params As String = vbNullString, _
Optional ByVal Directory As String = vbNullString, _
Optional ByVal State As shellOpenState = so_Norm) As Boolean
ShellExec = (ShellExecute(0, action, path, Params, Directory, State) >= 33)
End Function
Sub push(ary, value) 'this modifies parent ary object
On Error GoTo Init
Dim X
X = UBound(ary)
ReDim Preserve ary(X + 1)
If IsObject(value) Then
Set ary(X + 1) = value
Else
ary(X + 1) = value
End If
Exit Sub
Init:
ReDim ary(0)
If IsObject(value) Then
Set ary(0) = value
Else
ary(0) = value
End If
End Sub
Function pad(v, Optional L As Long = 8, Optional char As String = " ", Optional padRight As Boolean = True)
On Error GoTo hell
Dim X As Long
X = Len(v)
If X < L Then
If padRight Then
pad = v & String(L - X, char)
Else
pad = String(L - X, char) & v
End If
Else
hell:
pad = v
End If
End Function
Function FileExists(path) As Boolean
On Error GoTo hell
'.(0), ..(0) etc cause dir to read it as cwd!
If Len(path) = 0 Then Exit Function
If Right(path, 1) = "\" Then Exit Function
If InStr(path, Chr(0)) > 0 Then Exit Function
If Dir(path, vbHidden Or vbNormal Or vbReadOnly Or vbSystem) <> "" Then FileExists = True
Exit Function
hell: FileExists = False
End Function
Public Function FileSize(fPath As String) As String
Dim fsize As Long
Dim szName As String
On Error GoTo hell
fsize = FileLen(fPath)
szName = " bytes"
If fsize > 1024 Then
fsize = fsize / 1024
szName = " Kb"
End If
If fsize > 1024 Then
fsize = fsize / 1024
szName = " Mb"
End If
FileSize = fsize & szName
Exit Function
hell:
End Function
'=========================================================================
' VB Syntax Highlighting
'=========================================================================
Public Function SetVBHighlighter(sci As SciWrapper) As Boolean
On Error GoTo ErrorHandler
' ========================================================================
' Configure Scintilla for Visual Basic syntax highlighting
' Uses the VB lexer for VB6/VBA syntax
' ========================================================================
' VB Keywords - Primary keyword set (flow control, declarations, etc.)
Const KEYWORDS_PRIMARY = "and begin case call class continue do each else " & _
"elseif end erase error event exit false for function " & _
"get gosub goto if implement in load loop lset me mid " & _
"new next not nothing on or property raiseevent rem " & _
"resume return rset select set stop sub then to true " & _
"unload until wend while with withevents attribute alias " & _
"as boolean byref byte byval const compare currency date " & _
"declare dim double enum explicit friend global integer " & _
"let lib long module object option optional preserve " & _
"private public redim single static string type variant"
' VB Keywords - Secondary keyword set (statement keywords)
Const KEYWORDS_STATEMENT = "and begin case call class continue do each else " & _
"elseif end erase error event exit false for function " & _
"get gosub goto if implement in load loop lset me mid " & _
"new next not nothing on or property raiseevent rem " & _
"resume return rset select set stop sub then to true"
' Color constants for readability (BGR format)
' Const CLR_WHITE = &HFFFFFF
' Const CLR_BLACK = &H0
' Const CLR_DARK_GREEN = &H5500
' Const CLR_BLUE = &HFF
' Const CLR_DARK_BLUE = &HA00000
' Const CLR_PURPLE = &HC01090
' Const CLR_BROWN = &H8CA0
' Const CLR_TEAL = &H808000
' Const CLR_ORANGE = &H8080
' Const CLR_RED = &HFF0000
' Const CLR_TAN = &HBD7373
' Const CLR_LINE_NUM_BACK = &HEFEFF3
Const CLR_WHITE As Long = &HFFFFFF
Const CLR_BLACK As Long = &H0&
Const CLR_DARK_GREEN As Long = &H5500& ' Comments
Const CLR_BLUE As Long = &HFF& ' Brace mismatch / highlights
Const CLR_DARK_BLUE As Long = &HA00000 ' Class/function names
Const CLR_PURPLE As Long = &HC01090 ' Strings
Const CLR_BROWN As Long = &H8CA0& ' Doc comment keywords
Const CLR_TEAL As Long = &H808000 ' Numbers / operators
Const CLR_ORANGE As Long = &H8080& ' Preprocessor / misc
Const CLR_RED As Long = &HFF0000 ' Keywords
Const CLR_TAN As Long = &HBD7373 ' Line numbers
Const CLR_LINE_NUM_BACK As Long = &HEFEFF3 ' Line number background
With sci
' Initialize VB lexer
.style.Lexer = lexVB
.style.clearAll
.SciMsg 2090, 5 ' SCI_SETSTYLEBITS = 5
' Set keyword lists
.style.SetKeywords 0, KEYWORDS_PRIMARY
.style.SetKeywords 2, KEYWORDS_STATEMENT
' ------------------------------------------------------------------------
' Configure Default Style (STYLE_DEFAULT = 32)
' All other styles inherit from this unless explicitly overridden
' ------------------------------------------------------------------------
.style.SetFont 32, "Courier New"
.style.SetSize 32, 10
.style.SetFore 32, CLR_BLACK
.style.SetBack 32, CLR_WHITE
.style.SetBold 32, False
.style.SetItalic 32, False
.style.SetUnderline 32, False
.style.SetVisible 32, True
.style.SetEOLFilled 32, False
.style.clearAll ' Propagate default style to all
' ------------------------------------------------------------------------
' SCE_VB_DEFAULT (0) - Default text
' ------------------------------------------------------------------------
.style.SetFore 0, CLR_BLACK
' ------------------------------------------------------------------------
' SCE_VB_COMMENT (1) - Comments (REM or ')
' ------------------------------------------------------------------------
.style.SetFore 1, CLR_DARK_GREEN
' ------------------------------------------------------------------------
' SCE_VB_NUMBER (2) - Numeric literals
' ------------------------------------------------------------------------
.style.SetFore 2, CLR_BLUE
' ------------------------------------------------------------------------
' SCE_VB_KEYWORD (3) - Language keywords (bold dark blue)
' ------------------------------------------------------------------------
.style.SetFore 3, CLR_DARK_BLUE
.style.SetBold 3, True
' ------------------------------------------------------------------------
' SCE_VB_STRING (4) - String literals "..." (italic purple)
' ------------------------------------------------------------------------
.style.SetFore 4, CLR_PURPLE
.style.SetItalic 4, True
' ------------------------------------------------------------------------
' SCE_VB_PREPROCESSOR (5) - Preprocessor directives (#If, #Const, etc.)
' ------------------------------------------------------------------------
.style.SetFore 5, CLR_BROWN
' ------------------------------------------------------------------------
' SCE_VB_OPERATOR (6) - Operators (+, -, *, /, =, etc.) (bold teal)
' ------------------------------------------------------------------------
.style.SetFore 6, CLR_TEAL
.style.SetBold 6, True
' ------------------------------------------------------------------------
' SCE_VB_IDENTIFIER (7) - Identifiers (variable/function names)
' ------------------------------------------------------------------------
.style.SetFore 7, CLR_BLACK
' ------------------------------------------------------------------------
' SCE_VB_STRINGEOL (8) - Unclosed string at EOL (error state)
' ------------------------------------------------------------------------
.style.SetFore 8, CLR_ORANGE
' ------------------------------------------------------------------------
' STYLE_LINENUMBER (33) - Line number margin
' ------------------------------------------------------------------------
.style.SetFore 33, CLR_TAN
.style.SetBack 33, CLR_LINE_NUM_BACK
.style.SetSize 33, 8 ' Smaller font for line numbers
' ------------------------------------------------------------------------
' STYLE_BRACELIGHT (34) - Matching brace highlight
' ------------------------------------------------------------------------
.style.SetFore 34, CLR_RED
.style.SetBack 34, CLR_WHITE
.style.SetBold 34, True
' ------------------------------------------------------------------------
' STYLE_BRACEBAD (35) - Unmatched brace highlight
' ------------------------------------------------------------------------
.style.SetFore 35, CLR_BLUE
.style.SetBack 35, CLR_WHITE
.style.SetBold 35, True
' Apply syntax highlighting to entire document
.style.Colorise 0, -1
End With
SetVBHighlighter = True
Exit Function
ErrorHandler:
SetVBHighlighter = False
End Function
'=========================================================================
' JavaScript/Java Syntax Highlighting
'=========================================================================
Public Function SetJavaHighlighter(sci As SciWrapper) As Boolean
On Error GoTo ErrorHandler
' ========================================================================
' Configure Scintilla for JavaScript/Java syntax highlighting
' Uses the CPP lexer which handles C-style syntax
' ========================================================================
Dim i As Long
Const KEYWORDS = _
"break case catch class const continue debugger default delete do else " & _
"enum export extends false finally for function if import in instanceof " & _
"let new null return super switch this throw true try typeof var void " & _
"while with yield await async"
' ========================================================================
' Long-safe color constants (NO inline literals!)
' ========================================================================
Const CLR_WHITE As Long = &HFFFFFF
Const CLR_BLACK As Long = &H0&
Const CLR_GRAY As Long = &H808080
Const CLR_DARK_GREEN As Long = &H8000&
Const CLR_DARK_BLUE As Long = &H800000
Const CLR_PURPLE As Long = &H800080
Const CLR_TEAL As Long = &H808000
Const CLR_CYAN As Long = &HC08000
Const CLR_LIGHT_CYAN As Long = &HC0FFC0
Const CLR_LIGHT_YELLOW As Long = &HE0FFE0
Const CLR_LIGHT_PINK As Long = &HE0E0FF
Const CLR_LIGHT_BLUE As Long = &HFFC0C0
Const CLR_RED As Long = &HFF0000
Const CLR_BLUE As Long = &HFF&
Const CLR_ORANGE As Long = &H5080&
Const CLR_BROWN As Long = &H7080&
Const CLR_TAN As Long = &HBD7373
Const CLR_LINE_NUM_BACK As Long = &HEFEFF3
' Former inline literal colors
Const CLR_COMMENT_LINE As Long = &H7F00&
Const CLR_COMMENT_DOC As Long = &H555555
Const CLR_NUMBER_TEAL As Long = &H808000 ' same as CLR_TEAL
Const CLR_STRING_PURPLE As Long = &H850080
Const CLR_CHAR_PURPLE As Long = &H850080
Const CLR_UUID_CYAN As Long = &HC08000 ' same as CLR_CYAN
Const CLR_PREPROC_ORANGE As Long = &H8080&
Const CLR_OPERATOR_TEAL As Long = &H808000 ' same as CLR_TEAL
Const CLR_STRING_EOL_BACK As Long = &HFFC1FF
Const CLR_VERBATIM_BACK As Long = &HE0E0E0
Const CLR_REGEX_CYAN As Long = &HC000&
Const CLR_REGEX_BACK As Long = &HE0FFE0
Const CLR_WORD2_MAGENTA As Long = &HA00030
Const CLR_COMMENT_DOC_KEY As Long = &H7080&
Const CLR_COMMENT_DOC_ERR As Long = &HA00000
With sci
' Initialize lexer
.style.Lexer = lexCPP
.style.clearAll
.SciMsg 2090, 5 ' SCI_SETSTYLEBITS = 5
.SciSetProperty "lexer.cpp.track.preprocessor", "0"
.SciSetProperty "lexer.cpp.allow.dollars", "0"
.SciSetProperty "styling.within.preprocessor", "1"
' Set keyword list
.style.SetKeywords 0, KEYWORDS
' ------------------------------------------------------------------------
' Configure Default Style (STYLE_DEFAULT = 32)
' ------------------------------------------------------------------------
.style.SetFont 32, "Courier New"
.style.SetSize 32, 11
.style.SetFore 32, CLR_BLACK
.style.SetBack 32, CLR_WHITE
.style.SetBold 32, False
.style.SetItalic 32, False
.style.SetUnderline 32, False
.style.SetVisible 32, True
.style.SetEOLFilled 32, False
.style.clearAll ' Propagate default style to all
' ------------------------------------------------------------------------
' SCE_C_DEFAULT (0)
' ------------------------------------------------------------------------
.style.SetFore 0, CLR_GRAY
' ------------------------------------------------------------------------
' SCE_C_COMMENT (1) - Block comments /* ... */
' ------------------------------------------------------------------------
.style.SetFore 1, CLR_DARK_GREEN
' ------------------------------------------------------------------------
' SCE_C_COMMENTLINE (2) - Line comments //
' ------------------------------------------------------------------------
.style.SetFore 2, CLR_COMMENT_LINE
' ------------------------------------------------------------------------
' SCE_C_COMMENTDOC (3) - Documentation comments /** ... */
' ------------------------------------------------------------------------
.style.SetFore 3, CLR_COMMENT_DOC
' ------------------------------------------------------------------------
' SCE_C_NUMBER (4)
' ------------------------------------------------------------------------
.style.SetFore 4, CLR_NUMBER_TEAL
' ------------------------------------------------------------------------
' SCE_C_WORD (5) - Keywords
' ------------------------------------------------------------------------
.style.SetFore 5, CLR_DARK_BLUE
.style.SetBold 5, True
' ------------------------------------------------------------------------
' SCE_C_STRING (6)
' ------------------------------------------------------------------------
.style.SetFore 6, CLR_STRING_PURPLE
.style.SetItalic 6, True
' ------------------------------------------------------------------------
' SCE_C_CHARACTER (7)
' ------------------------------------------------------------------------
.style.SetFore 7, CLR_CHAR_PURPLE
.style.SetItalic 7, True
' ------------------------------------------------------------------------
' SCE_C_UUID (8)
' ------------------------------------------------------------------------
.style.SetFore 8, CLR_UUID_CYAN
' ------------------------------------------------------------------------
' SCE_C_PREPROCESSOR (9)
' ------------------------------------------------------------------------
.style.SetFore 9, CLR_PREPROC_ORANGE
' ------------------------------------------------------------------------
' SCE_C_OPERATOR (10)
' ------------------------------------------------------------------------
.style.SetFore 10, CLR_OPERATOR_TEAL
' ------------------------------------------------------------------------
' SCE_C_STRINGEOL (12)
' ------------------------------------------------------------------------
.style.SetFore 12, CLR_BLACK
.style.SetBack 12, CLR_STRING_EOL_BACK
.style.SetEOLFilled 12, True
' ------------------------------------------------------------------------
' SCE_C_VERBATIM (13)
' ------------------------------------------------------------------------
.style.SetFore 13, CLR_DARK_GREEN
.style.SetBack 13, CLR_VERBATIM_BACK
' ------------------------------------------------------------------------
' SCE_C_REGEX (14)
' ------------------------------------------------------------------------
.style.SetFore 14, CLR_REGEX_CYAN
.style.SetBack 14, CLR_REGEX_BACK
' ------------------------------------------------------------------------
' SCE_C_COMMENTLINEDOC (15)
' ------------------------------------------------------------------------
.style.SetFore 15, CLR_DARK_GREEN
' ------------------------------------------------------------------------
' SCE_C_WORD2 (16)
' ------------------------------------------------------------------------
.style.SetFore 16, CLR_WORD2_MAGENTA
' ------------------------------------------------------------------------
' SCE_C_COMMENTDOCKEYWORD (17)
' ------------------------------------------------------------------------
.style.SetFore 17, CLR_COMMENT_DOC_KEY
' ------------------------------------------------------------------------
' SCE_C_COMMENTDOCKEYWORDERROR (18)
' ------------------------------------------------------------------------
.style.SetFore 18, CLR_COMMENT_DOC_ERR
' ------------------------------------------------------------------------
' STYLE_LINENUMBER (33)
' ------------------------------------------------------------------------
.style.SetFore 33, CLR_TAN
.style.SetBack 33, CLR_LINE_NUM_BACK
' ------------------------------------------------------------------------
' STYLE_BRACELIGHT (34)
' ------------------------------------------------------------------------
.style.SetFore 34, CLR_RED
.style.SetBack 34, CLR_WHITE
.style.SetBold 34, True
' ------------------------------------------------------------------------
' STYLE_BRACEBAD (35)
' ------------------------------------------------------------------------
.style.SetFore 35, CLR_BLUE
.style.SetBack 35, CLR_WHITE
.style.SetBold 35, True
' Apply syntax highlighting
.style.Colorise 0, -1
End With
SetJavaHighlighter = True
Exit Function
ErrorHandler:
SetJavaHighlighter = False
End Function
Public Function SetSqlHighlighter(sci As SciWrapper) As Boolean
On Error GoTo ErrorHandler
' ========================================================================
' Configure Scintilla for SQL syntax highlighting
' Supports T-SQL, PL/SQL, and standard SQL syntax
' ========================================================================
' SQL Keywords - Commands, clauses, operators, and data types
Const SQL_KEYWORDS = "select from where and or not in like between is null " & _
"order by group having insert update delete create alter drop " & _
"table index view primary key foreign references constraint " & _
"inner outer left right join union distinct as " & _
"count sum avg max min desc asc into values set " & _
"declare begin end if else while loop cursor open fetch close " & _
"deallocate procedure function returns return exec execute trigger " & _
"varchar int bigint datetime char text nvarchar nchar " & _
"float decimal numeric bit date time timestamp"
' Color constants (BGR format)
Const CLR_WHITE = &HFFFFFF
Const CLR_BLACK = &H0
Const CLR_GREEN = &H8000 ' Dark green for comments
Const CLR_BLUE = &HFF ' Bright blue for keywords
Const CLR_PURPLE = &H850080 ' Purple for strings
Const CLR_TEAL = &H808000 ' Teal for numbers/operators
Const CLR_RED = &HFF0000 ' Red for brace matching
Const CLR_TAN = &HBD7373 ' Tan for line numbers
Const CLR_LINE_NUM_BACK = &HEFEFF3
With sci
' Initialize SQL lexer
.style.Lexer = lexSQL
.style.clearAll
.SciMsg 2090, 5 ' SCI_SETSTYLEBITS = 5
' Set SQL keyword list
.style.SetKeywords 0, SQL_KEYWORDS
' ------------------------------------------------------------------------
' Configure Default Style (STYLE_DEFAULT = 32)
' All other styles inherit from this unless explicitly overridden
' ------------------------------------------------------------------------
.style.SetFont 32, "Courier New"
.style.SetSize 32, 10
.style.SetFore 32, CLR_BLACK
.style.SetBack 32, CLR_WHITE
.style.SetBold 32, False
.style.SetItalic 32, False
.style.SetUnderline 32, False
.style.SetVisible 32, True
.style.SetEOLFilled 32, False
.style.clearAll ' Propagate default style to all
' ------------------------------------------------------------------------
' SCE_SQL_DEFAULT (0) - Default text
' ------------------------------------------------------------------------
.style.SetFore 0, CLR_BLACK
' ------------------------------------------------------------------------
' SCE_SQL_COMMENT (1) - Block comments /* ... */
' ------------------------------------------------------------------------
.style.SetFore 1, CLR_GREEN
' ------------------------------------------------------------------------
' SCE_SQL_COMMENTLINE (2) - Line comments --
' ------------------------------------------------------------------------
.style.SetFore 2, CLR_GREEN
' ------------------------------------------------------------------------
' SCE_SQL_NUMBER (3) - Numeric literals
' ------------------------------------------------------------------------
.style.SetFore 3, CLR_TEAL
' ------------------------------------------------------------------------
' SCE_SQL_STRING (4) - String literals '...' (italic purple)
' ------------------------------------------------------------------------
.style.SetFore 4, CLR_PURPLE
.style.SetItalic 4, True
' ------------------------------------------------------------------------
' SCE_SQL_WORD (5) - SQL keywords (bold blue)
' SELECT, FROM, WHERE, JOIN, etc.
' ------------------------------------------------------------------------
.style.SetFore 5, CLR_BLUE
.style.SetBold 5, True
' ------------------------------------------------------------------------
' SCE_SQL_OPERATOR (6) - Operators and punctuation
' =, <>, +, -, *, /, %, etc.
' ------------------------------------------------------------------------
.style.SetFore 6, CLR_TEAL
' ------------------------------------------------------------------------
' SCE_SQL_IDENTIFIER (7) - Identifiers (table/column names)
' ------------------------------------------------------------------------
.style.SetFore 7, CLR_BLACK
' ------------------------------------------------------------------------
' STYLE_LINENUMBER (33) - Line number margin
' ------------------------------------------------------------------------
.style.SetFore 33, CLR_TAN
.style.SetBack 33, CLR_LINE_NUM_BACK
.style.SetSize 33, 8 ' Smaller font for line numbers
' ------------------------------------------------------------------------
' STYLE_BRACELIGHT (34) - Matching parenthesis/bracket highlight
' ------------------------------------------------------------------------
.style.SetFore 34, CLR_RED
.style.SetBack 34, CLR_WHITE
.style.SetBold 34, True
' ------------------------------------------------------------------------
' STYLE_BRACEBAD (35) - Unmatched parenthesis/bracket highlight
' ------------------------------------------------------------------------
.style.SetFore 35, CLR_BLUE
.style.SetBack 35, CLR_WHITE
.style.SetBold 35, True
' Apply syntax highlighting to entire document
.style.Colorise 0, -1
End With
SetSqlHighlighter = True
Exit Function
ErrorHandler:
SetSqlHighlighter = False
End Function
'=========================================================================
' VB P-Code Disassembly Highlighting (for your malware analysis work!)
'=========================================================================
Public Sub SetVBPCodeHighlighter(sci As SciWrapper, Optional additionalKeywords As String = "")
Dim callOpcodes As String
Dim branchOpcodes As String
Dim mathFileOpcodes As String
' Set CPP lexer for C-style syntax
sci.style.Lexer = lexCPP
sci.style.clearAll
' Configure base font
sci.style.SetFont 32, "Courier New"
sci.style.SetSize 32, 10
sci.style.SetBack 32, &HFFFFFF
sci.style.SetFore 32, &H0
sci.style.clearAll
' Function call opcodes (keywords set 0)
callOpcodes = "CallI2 CallI4 CallR4 CallR8 CallCy CallVar CallStr CallBool CallDate " & _
"CallFunc CallHresult CallSt CallStByref CallFFP4 CallFFP8 ReturnHresult " & _
"FStCall FStCallFFP4 FStCallFFP8 QuoteRem"
' Branch/comparison opcodes (keywords set 1)
branchOpcodes = "BranchF BranchT Branch BranchFVar OnErrorGoto OnErrorResumeNext BoS BranchFVarFree BranchTVar " & _
"BranchTVarFree Gosub Resume OnGosub OnGoto EqI2 EqI4 EqR8 EqCy EqVar EqStr EqTextVar EqTextStr " & _
"EqVarBool EqTextVarBool EqCyR8 NeUI1 NeI4 NeR4 NeCy NeVar NeStr NeTextVar NeTextStr NeVarBool " & _
"NeTextVarBool NeCyR8 LeUI1 LeI2 LeI4 LeR4 LeCy LeVar LeStr LeTextVar LeTextStr LeVarBool " & _
"LeTextVarBool LeCyR8 GeUI1 GeI2 GeI4 GeR4 GeCy GeVar GeStr GeTextVar GeTextStr GeVarBool " & _
"GeTextVarBool GeCyR8 LtUI1 LtI2 LtI4 LtR4 LtCy LtVar LtStr LtTextVar LtTextStr LtVarBool " & _
"LtTextVarBool LtCyR8 GtUI1 GtI2 GtI4 GtR4 GtCy GtVar GtStr GtTextVar GtTextStr GtVarBool " & _
"GtTextVarBool GtCyR8 LikeVar LikeStr LikeTextVar LikeTextStr LikeVarBool LikeTextVarBool " & _
"BetweenUI1 BetweenI2 BetweenI4 BetweenR4 BetweenCy BetweenVar BetweenStr BetweenTextVar " & _
"BetweenTextStr EqR4 NeI2 NeR8 LtR8 LeR8 GeR8 ForUI1 ForI2 ForI4 ForR4 ForR8 ForCy ForVar " & _
"ForStepUI1 ForStepI2 ForStepI4 ForStepR4 ForStepR8 ForStepCy ForStepVar ForEachCollVar " & _
"NextEachCollVar ForEachCollAd NextEachCollAd ForEachAryVar NextEachAryVar NextUI1 NextI2 " & _
"NextI4 NextStepR4 NextR8 NextStepCy NextStepVar InvalidExcode NextStepUI1 NextStepI2 " & _
"NextStepI4 ForEachCollObj ForEachVar ForEachVarFree NextEachCollObj NextEachVar NextStepR8 " & _
"ExitForCollObj ExitForAryVar ExitForVar"
' Math/file operations (keywords set 3)
If Len(additionalKeywords) = 0 Then
mathFileOpcodes = "ModI2 ModI4 NotI4 AndI4 OrI4 XorI4 XorVar OrI2 OrVar AndUI1 AndVar ModUI1 ModVar NotUI1 " & _
"SeekFile NameFile OpenFile LockFile PrintFile WriteFile InputFile Input InputDone " & _
"InputItemUI1 InputItemI2 InputItemI4 InputItemR4 InputItemR8 InputItemCy InputItemVar " & _
"InputItemStr InputItemBool InputItemDate LineInputVar LineInputStr WriteChan Close " & _
"CloseAll GetRec3 GetRec4 PutRec3 PutRec4 GetRecOwner3 GetRecOwner4 PutRecOwner3 " & _
"PutRecOwner4 GetRecOwn3 GetRecOwn4 PutRecOwn3 PutRecOwn4"
Else
mathFileOpcodes = additionalKeywords
End If
' Set keywords
sci.style.SetKeywords 0, callOpcodes
sci.style.SetKeywords 1, branchOpcodes
sci.style.SetKeywords 3, mathFileOpcodes
' Set colors - optimized for malware analysis readability
sci.style.SetFore SCE_C_COMMENT, &H8000 ' Green comments
sci.style.SetFore SCE_C_COMMENTLINE, &H8000
sci.style.SetFore SCE_C_WORD, &H800000 ' Dark red for calls
sci.style.SetFore SCE_C_WORD2, vbRed ' Red for branches
sci.style.SetFore SCE_C_GLOBALCLASS, &H25208D ' Purple for custom keywords
sci.style.SetFore SCE_C_STRING, &H800080 ' Purple strings
sci.style.SetFore SCE_C_CHARACTER, &H800080
sci.style.SetFore SCE_C_NUMBER, &H8000 ' Blue numbers
' Set bold for emphasis
sci.style.SetBold SCE_C_WORD, True
sci.style.SetBold SCE_C_WORD2, True
sci.style.SetBold SCE_C_GLOBALCLASS, True
sci.style.Colorise 0, -1
End Sub
Public Function SetPythonHighlighter(sci As SciWrapper) As Boolean
On Error GoTo ErrorHandler
' ========================================================================
' Configure Scintilla for Python syntax highlighting
' Supports Python 2.x and 3.x syntax
' ========================================================================
' Python Keywords - Language keywords and built-in constants
Const PYTHON_KEYWORDS = "and as assert break class continue def del elif else except " & _
"exec finally for from global if import in is lambda not or " & _
"pass print raise return try while with yield True False None"
' Color constants (BGR format)
' Const CLR_WHITE = &HFFFFFF
' Const CLR_BLACK = &H0
' Const CLR_DARK_GREEN = &H8000 ' Comments
' Const CLR_DARK_CYAN = &H808000 ' Numbers
' Const CLR_PURPLE = &H800080 ' Strings
' Const CLR_GRAY = &H808080 ' Triple-quoted strings/docstrings
' Const CLR_RED = &HFF0000 ' Keywords
' Const CLR_DARK_BLUE = &H800000 ' Function/class names
' Const CLR_BLUE = &HFF ' Brace mismatch
' Const CLR_TAN = &HBD7373 ' Line numbers
' Const CLR_LINE_NUM_BACK = &HEFEFF3
Const CLR_WHITE As Long = &HFFFFFF
Const CLR_BLACK As Long = &H0&
Const CLR_DARK_GREEN As Long = &H8000& ' Comments
Const CLR_DARK_CYAN As Long = &H808000 ' Numbers
Const CLR_PURPLE As Long = &H800080 ' Strings
Const CLR_GRAY As Long = &H808080 ' Triple-quoted/docstrings
Const CLR_RED As Long = &HFF0000 ' Keywords
Const CLR_DARK_BLUE As Long = &H800000 ' Function/class names
Const CLR_BLUE As Long = &HFF& ' Brace mismatch
Const CLR_TAN As Long = &HBD7373 ' Line numbers
Const CLR_LINE_NUM_BACK As Long = &HEFEFF3 ' Line number background
With sci
' Initialize Python lexer
.style.Lexer = lexPython
.style.clearAll
' Set Python keyword list
.style.SetKeywords 0, PYTHON_KEYWORDS
' ------------------------------------------------------------------------
' Configure Default Style (STYLE_DEFAULT = 32)
' Using Consolas for better readability with Python's significant whitespace
' ------------------------------------------------------------------------
.style.SetFont 32, "Consolas"
.style.SetSize 32, 10
.style.SetFore 32, CLR_BLACK
.style.SetBack 32, CLR_WHITE
.style.SetBold 32, False
.style.SetItalic 32, False
.style.SetUnderline 32, False
.style.SetVisible 32, True
.style.SetEOLFilled 32, False
.style.clearAll ' Propagate default style to all
' ------------------------------------------------------------------------
' SCE_P_DEFAULT (0) - Default text
' ------------------------------------------------------------------------
.style.SetFore 0, CLR_BLACK
' ------------------------------------------------------------------------
' SCE_P_COMMENTLINE (1) - Comments (# ...)
' ------------------------------------------------------------------------
.style.SetFore 1, CLR_DARK_GREEN
.style.SetItalic 1, True
' ------------------------------------------------------------------------
' SCE_P_NUMBER (2) - Numeric literals (int, float, hex, octal, binary)
' ------------------------------------------------------------------------
.style.SetFore 2, CLR_DARK_CYAN
' ------------------------------------------------------------------------
' SCE_P_STRING (3) - String literals (double quotes "...")
' ------------------------------------------------------------------------
.style.SetFore 3, CLR_PURPLE
' ------------------------------------------------------------------------
' SCE_P_CHARACTER (4) - String literals (single quotes '...')
' ------------------------------------------------------------------------
.style.SetFore 4, CLR_PURPLE
' ------------------------------------------------------------------------
' SCE_P_WORD (5) - Keywords (bold red)
' if, for, while, def, class, import, etc.
' ------------------------------------------------------------------------
.style.SetFore 5, CLR_RED
.style.SetBold 5, True
' ------------------------------------------------------------------------
' SCE_P_TRIPLE (6) - Triple single-quoted strings ('''...''')
' Used for multi-line strings and docstrings
' ------------------------------------------------------------------------
.style.SetFore 6, CLR_GRAY
' ------------------------------------------------------------------------
' SCE_P_TRIPLEDOUBLE (7) - Triple double-quoted strings ("""...""")
' Used for multi-line strings and docstrings
' ------------------------------------------------------------------------
.style.SetFore 7, CLR_GRAY
' ------------------------------------------------------------------------
' SCE_P_CLASSNAME (8) - Class name definition (bold dark green)
' Name following 'class' keyword
' ------------------------------------------------------------------------
.style.SetFore 8, CLR_DARK_GREEN
.style.SetBold 8, True
' ------------------------------------------------------------------------
' SCE_P_DEFNAME (9) - Function/method name definition (bold dark blue)
' Name following 'def' keyword
' ------------------------------------------------------------------------
.style.SetFore 9, CLR_DARK_BLUE
.style.SetBold 9, True
' ------------------------------------------------------------------------
' SCE_P_OPERATOR (10) - Operators and punctuation
' +, -, *, /, =, ==, :, etc.
' ------------------------------------------------------------------------
.style.SetFore 10, CLR_BLACK
' ------------------------------------------------------------------------
' SCE_P_IDENTIFIER (11) - Identifiers (variable names, function calls)
' ------------------------------------------------------------------------
.style.SetFore 11, CLR_BLACK
' ------------------------------------------------------------------------
' STYLE_LINENUMBER (33) - Line number margin
' ------------------------------------------------------------------------
.style.SetFore 33, CLR_TAN
.style.SetBack 33, CLR_LINE_NUM_BACK
.style.SetSize 33, 8 ' Smaller font for line numbers
' ------------------------------------------------------------------------
' STYLE_BRACELIGHT (34) - Matching parenthesis/bracket highlight
' Important for Python's tuple/list/dict syntax
' ------------------------------------------------------------------------
.style.SetFore 34, CLR_RED
.style.SetBack 34, CLR_WHITE
.style.SetBold 34, True
' ------------------------------------------------------------------------
' STYLE_BRACEBAD (35) - Unmatched parenthesis/bracket highlight
' ------------------------------------------------------------------------
.style.SetFore 35, CLR_BLUE
.style.SetBack 35, CLR_WHITE
.style.SetBold 35, True
' Apply syntax highlighting to entire document
.style.Colorise 0, -1
End With
SetPythonHighlighter = True
Exit Function
ErrorHandler:
SetPythonHighlighter = False
End Function
'=========================================================================
' HTML/XML Syntax Highlighting
'=========================================================================
Public Function SetHTMLHighlighter(sci As SciWrapper) As Boolean
On Error GoTo ErrorHandler
sci.style.Lexer = lexHTML
sci.style.clearAll
sci.SciMsg 2090, 7 ' SCI_SETSTYLEBITS = 7 for HTML
sci.style.SetFont 32, "Consolas"
sci.style.SetSize 32, 10
sci.style.SetBack 32, &HFFFFFF
sci.style.clearAll
' HTML styles
sci.style.SetFore 1, &H8000 ' Tag - green
sci.style.SetFore 2, &HFF0000 ' Unknown tag - blue
sci.style.SetFore 3, &H800080 ' Attribute - purple
sci.style.SetFore 4, &H8000 ' Unknown attribute
sci.style.SetFore 5, &HFF ' Number - red
sci.style.SetFore 6, &H800080 ' Double string
sci.style.SetFore 7, &H800080 ' Single string
sci.style.SetFore 8, &H808080 ' Other
sci.style.SetFore 9, &H8000 ' Comment - green
sci.style.SetItalic 9, True
sci.style.Colorise 0, -1
SetHTMLHighlighter = True
Exit Function
ErrorHandler:
SetHTMLHighlighter = False
End Function
'=========================================================================
' Utility: Configure Default Editor Settings
'=========================================================================
Public Sub ConfigureDefaultEditorSettings(sci As SciWrapper)
With sci
' Margins
.Margins.ConfigureLineNumbers 0, 40
.Margins.ConfigureFolding 1, 16
' Editor preferences
.edit.TabWidth = 4
.edit.UseTabs = False
.edit.TabIndents = True
.edit.BackspaceUnindents = True
.edit.eolMode = eolCRLF ' VB6 standard
' View settings
.View.CaretLineVisible = True
.View.CaretLineBack = &HE8E8E8
.View.EdgeMode = edgeLine
.View.EdgeColumn = 80
.View.EdgeColor = &HE0E0E0
' Whitespace
.View.ViewWhitespace = wsInvisible
' Caret
.View.CaretWidth = 1
.View.CaretPeriod = 500
End With
End Sub
'=========================================================================
' Utility: Apply Dark Theme (for late-night reverse engineering!)
'=========================================================================
Public Sub ApplyDarkTheme(sci As SciWrapper)
With sci
' Dark background, light text
.style.SetBack 32, &H1E1E1E ' Dark gray background
.style.SetFore 32, &HE0E0E0 ' Light gray text
.style.SetFont 32, "Consolas"
.style.SetSize 32, 10
.style.clearAll
' Line number margin
.Margins.SetBack 0, &H2D2D2D
' Caret line
.View.CaretLineVisible = True
.View.CaretLineBack = &H2D2D30
.View.CaretLineBackAlpha = 128
' Caret color
.View.CaretFore = &HFFFFFF
' Edge column
.View.EdgeColor = &H3E3E42
' Selection colors
.SciMsg 2067, &H3E3E42 ' SCI_SETSELBACK with useSetting=True
.SciMsg 2068, &HFFFFFF ' SCI_SETSELFORE
End With
End Sub