From 5b8033848ef6438a7e564ef4408feb1e10206453 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 3 Dec 2023 15:16:15 +0100 Subject: [PATCH] SynEdit: ini Highlighter, support optional # comments (cherry picked from commit c1ab55df5f12b80ad4adca8009d1ac19ffa521e2) --- components/synedit/synhighlighterini.pas | 32 +++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/components/synedit/synhighlighterini.pas b/components/synedit/synhighlighterini.pas index 2a323bc84b..87cfb0bde1 100644 --- a/components/synedit/synhighlighterini.pas +++ b/components/synedit/synhighlighterini.pas @@ -60,11 +60,14 @@ type TProcTableProc = procedure of object; type + TSynIniCommentType = (ictSemicolon, ictHash); // TODO ictSemicolonMidLine, ictHashMidline + TSynIniCommentTypes = set of TSynIniCommentType; { TSynIniSyn } TSynIniSyn = class(TSynCustomHighlighter) private + FCommentTypes: TSynIniCommentTypes; fLine: PChar; fLineNumber: Integer; fProcTable: array[#0..#255] of TProcTableProc; @@ -79,6 +82,7 @@ type fSpaceAttri: TSynHighlighterAttributes; fStringAttri: TSynHighlighterAttributes; fSymbolAttri: TSynHighlighterAttributes; + procedure SetCommentTypes(AValue: TSynIniCommentTypes); procedure SectionOpenProc; procedure KeyProc; procedure CRProc; @@ -87,7 +91,7 @@ type procedure LFProc; procedure NullProc; procedure NumberProc; - procedure SemiColonProc; + procedure CommentProc; procedure SpaceProc; procedure StringProc; // "" procedure StringProc1; // '' @@ -112,6 +116,7 @@ type function GetTokenPos: Integer; override; procedure Next; override; published + property CommentTypes: TSynIniCommentTypes read FCommentTypes write SetCommentTypes default [ictSemicolon]; property CommentAttri: TSynHighlighterAttributes read fCommentAttri write fCommentAttri; property TextAttri : TSynHighlighterAttributes read fTextAttri @@ -144,7 +149,18 @@ begin #34 {"} : fProcTable[i] := @StringProc; #39 {'} : fProcTable[i] := @StringProc1; '0'..'9': fProcTable[i] := @NumberProc; - #59 {;} : fProcTable[i] := @SemiColonProc; + #59 {;} : begin + if ictSemicolon in FCommentTypes then + fProcTable[i] := @CommentProc + else + fProcTable[i] := @TextProc; + end; + '#': begin + if ictHash in FCommentTypes then + fProcTable[i] := @CommentProc + else + fProcTable[i] := @TextProc; + end; #61 {=} : fProcTable[i] := @EqualProc; #91 {[} : fProcTable[i] := @SectionOpenProc; #1..#9, #11, #12, #14..#32: fProcTable[i] := @SpaceProc; @@ -180,6 +196,7 @@ begin SetAttributesOnChange(@DefHighlightChange); fDefaultFilter := SYNS_FilterINI; + FCommentTypes := [ictSemicolon]; MakeMethodTables; end; { Create } @@ -229,6 +246,15 @@ begin fTokenID := tkSymbol; end; +procedure TSynIniSyn.SetCommentTypes(AValue: TSynIniCommentTypes); +begin + if FCommentTypes = AValue then Exit; + FCommentTypes := AValue; + MakeMethodTables; + FAttributeChangeNeedScan := True; + DefHighlightChange(self); +end; + procedure TSynIniSyn.KeyProc; begin fTokenID := tkKey; @@ -280,7 +306,7 @@ begin end; // ; -procedure TSynIniSyn.SemiColonProc; +procedure TSynIniSyn.CommentProc; begin // if it is not column 0 mark as tkText and get out of here if Run > 0 then