SynEdit: ini Highlighter, support optional # comments

(cherry picked from commit c1ab55df5f)
This commit is contained in:
Martin 2023-12-03 15:16:15 +01:00
parent 291d78e391
commit 5b8033848e

View File

@ -60,11 +60,14 @@ type
TProcTableProc = procedure of object; TProcTableProc = procedure of object;
type type
TSynIniCommentType = (ictSemicolon, ictHash); // TODO ictSemicolonMidLine, ictHashMidline
TSynIniCommentTypes = set of TSynIniCommentType;
{ TSynIniSyn } { TSynIniSyn }
TSynIniSyn = class(TSynCustomHighlighter) TSynIniSyn = class(TSynCustomHighlighter)
private private
FCommentTypes: TSynIniCommentTypes;
fLine: PChar; fLine: PChar;
fLineNumber: Integer; fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc; fProcTable: array[#0..#255] of TProcTableProc;
@ -79,6 +82,7 @@ type
fSpaceAttri: TSynHighlighterAttributes; fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes; fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes; fSymbolAttri: TSynHighlighterAttributes;
procedure SetCommentTypes(AValue: TSynIniCommentTypes);
procedure SectionOpenProc; procedure SectionOpenProc;
procedure KeyProc; procedure KeyProc;
procedure CRProc; procedure CRProc;
@ -87,7 +91,7 @@ type
procedure LFProc; procedure LFProc;
procedure NullProc; procedure NullProc;
procedure NumberProc; procedure NumberProc;
procedure SemiColonProc; procedure CommentProc;
procedure SpaceProc; procedure SpaceProc;
procedure StringProc; // "" procedure StringProc; // ""
procedure StringProc1; // '' procedure StringProc1; // ''
@ -112,6 +116,7 @@ type
function GetTokenPos: Integer; override; function GetTokenPos: Integer; override;
procedure Next; override; procedure Next; override;
published published
property CommentTypes: TSynIniCommentTypes read FCommentTypes write SetCommentTypes default [ictSemicolon];
property CommentAttri: TSynHighlighterAttributes read fCommentAttri property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri; write fCommentAttri;
property TextAttri : TSynHighlighterAttributes read fTextAttri property TextAttri : TSynHighlighterAttributes read fTextAttri
@ -144,7 +149,18 @@ begin
#34 {"} : fProcTable[i] := @StringProc; #34 {"} : fProcTable[i] := @StringProc;
#39 {'} : fProcTable[i] := @StringProc1; #39 {'} : fProcTable[i] := @StringProc1;
'0'..'9': fProcTable[i] := @NumberProc; '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; #61 {=} : fProcTable[i] := @EqualProc;
#91 {[} : fProcTable[i] := @SectionOpenProc; #91 {[} : fProcTable[i] := @SectionOpenProc;
#1..#9, #11, #12, #14..#32: fProcTable[i] := @SpaceProc; #1..#9, #11, #12, #14..#32: fProcTable[i] := @SpaceProc;
@ -180,6 +196,7 @@ begin
SetAttributesOnChange(@DefHighlightChange); SetAttributesOnChange(@DefHighlightChange);
fDefaultFilter := SYNS_FilterINI; fDefaultFilter := SYNS_FilterINI;
FCommentTypes := [ictSemicolon];
MakeMethodTables; MakeMethodTables;
end; { Create } end; { Create }
@ -229,6 +246,15 @@ begin
fTokenID := tkSymbol; fTokenID := tkSymbol;
end; end;
procedure TSynIniSyn.SetCommentTypes(AValue: TSynIniCommentTypes);
begin
if FCommentTypes = AValue then Exit;
FCommentTypes := AValue;
MakeMethodTables;
FAttributeChangeNeedScan := True;
DefHighlightChange(self);
end;
procedure TSynIniSyn.KeyProc; procedure TSynIniSyn.KeyProc;
begin begin
fTokenID := tkKey; fTokenID := tkKey;
@ -280,7 +306,7 @@ begin
end; end;
// ; // ;
procedure TSynIniSyn.SemiColonProc; procedure TSynIniSyn.CommentProc;
begin begin
// if it is not column 0 mark as tkText and get out of here // if it is not column 0 mark as tkText and get out of here
if Run > 0 then if Run > 0 then