highlighter, asm attribs set directly in Next();

This commit is contained in:
Basile Burg 2016-03-28 09:06:38 +02:00
parent 10da14cb73
commit cece2ad6d8
1 changed files with 17 additions and 33 deletions

View File

@ -61,23 +61,17 @@ type
function find(const aValue: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} function find(const aValue: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
end; end;
TTokenKind = (tkCommt, tkIdent, tkKeywd, tkStrng, tkBlank, tkSymbl, tkNumbr, tkDDocs, tkSpecK, tkError); TTokenKind = (tkCommt, tkIdent, tkKeywd, tkStrng, tkBlank, tkSymbl, tkNumbr,
tkDDocs, tkSpecK, tkError, tkAsmbl);
TRangeKind = (rkString1, rkString2, rkTokString, rkBlockCom1, rkBlockCom2, rkBlockDoc1, rkBlockDoc2, rkAsm); TRangeKind = (rkString1, rkString2, rkTokString, rkBlockCom1, rkBlockCom2,
rkBlockDoc1, rkBlockDoc2, rkAsm);
// a terminal range kind, cannot be combined with another range kind.
TPrimaryRange = (prNone, prString1, prString2, prBlockCom1, prBlockCom2, prBlockDoc1, prBlockDoc2);
// can be combined to a primary range
TSecondaryRange = (srNone, srTokenString, srActiveVersion, srInactiveVersion, srAssembly);
// used by the secondary ranges to transform the standard token attributes.
TAttributeTransform = (taFontStyle, taFontColor, taBackColor);
TRangeKinds = set of TRangeKind; TRangeKinds = set of TRangeKind;
// defines the ranges which can be folded // defines the ranges which can be folded
TFoldKinds = set of (fkBrackets, fkComments1, fkComments2, fkStrings, fkRegion, fkDDoc); TFoldKinds = set of (fkBrackets, fkComments1, fkComments2, fkStrings, fkRegion,
fkDDoc);
// internal class used to keep trace of the useful informations of the previous line // internal class used to keep trace of the useful informations of the previous line
TSynD2SynRange = class(TSynCustomHighlighterRange) TSynD2SynRange = class(TSynCustomHighlighterRange)
@ -86,8 +80,6 @@ type
nestedCommentsCount: Integer; nestedCommentsCount: Integer;
tokenStringBracketsCount: Integer; tokenStringBracketsCount: Integer;
rangeKinds: TRangeKinds; rangeKinds: TRangeKinds;
primaryRange: TPrimaryRange;
secondaryRange: TSecondaryRange;
// double quoted multi-line string prefixed with 'r': // double quoted multi-line string prefixed with 'r':
// => don't skip '"' following '\' // => don't skip '"' following '\'
rString: boolean; rString: boolean;
@ -265,9 +257,6 @@ begin
tokenStringBracketsCount := 0; tokenStringBracketsCount := 0;
rangeKinds := []; rangeKinds := [];
rString := false; rString := false;
//
primaryRange := prNone;
secondaryRange := srNone;
end; end;
procedure TSynD2SynRange.copyFrom(aSource: TSynD2SynRange); procedure TSynD2SynRange.copyFrom(aSource: TSynD2SynRange);
@ -277,9 +266,6 @@ begin
tokenStringBracketsCount := aSource.tokenStringBracketsCount; tokenStringBracketsCount := aSource.tokenStringBracketsCount;
rangeKinds := aSource.rangeKinds; rangeKinds := aSource.rangeKinds;
rString := aSource.rString; rString := aSource.rString;
//
primaryRange := aSource.primaryRange;
secondaryRange := aSource.secondaryRange;
end; end;
constructor TSynD2Syn.create(aOwner: TComponent); constructor TSynD2Syn.create(aOwner: TComponent);
@ -351,6 +337,7 @@ begin
fAttribLut[TTokenKind.tkDDocs] := fDDocsAttrib; fAttribLut[TTokenKind.tkDDocs] := fDDocsAttrib;
fAttribLut[TTokenKind.tkSpecK] := fSpeckAttrib; fAttribLut[TTokenKind.tkSpecK] := fSpeckAttrib;
fAttribLut[TTokenKind.tkError] := fErrorAttrib; fAttribLut[TTokenKind.tkError] := fErrorAttrib;
fAttribLut[TTokenKind.tkAsmbl] := fAsblrAttrib;
SetAttributesOnChange(@doAttribChange); SetAttributesOnChange(@doAttribChange);
fTokStop := 1; fTokStop := 1;
@ -882,7 +869,8 @@ begin
begin begin
fTokKind := tkSymbl; fTokKind := tkSymbl;
while isOperator1(readerNext^) do while isOperator1(readerNext^) do
if fTokStop - fTokStart = 4 then break; if (fTokStop - fTokStart = 4) or (reader^= #10) then
break;
if (fTokStop - fTokStart = 4) then if (fTokStop - fTokStart = 4) then
begin begin
if isOperator4(fLineBuf[fTokStart..fTokStart+3]) then if isOperator4(fLineBuf[fTokStart..fTokStart+3]) then
@ -949,13 +937,15 @@ begin
if isOperator1(reader^) then break; if isOperator1(reader^) then break;
end; end;
if fKeyWords.find(fLineBuf[FTokStart..fTokStop-1]) then if fKeyWords.find(fLineBuf[FTokStart..fTokStop-1]) then
fTokKind := tkKeywd begin
else if fSpecKw.find(fLineBuf[FTokStart..fTokStop-1]) then fTokKind := tkKeywd;
fTokKind := tkSpecK; if (fLineBuf[FTokStart..fTokStop-1] = 'asm') then
//check asm range
if fTokKind = tkKeywd then
if fLineBuf[FTokStart..fTokStop-1] = 'asm' then
fCurrRange.rangeKinds += [rkAsm]; fCurrRange.rangeKinds += [rkAsm];
end
else if fSpecKw.find(fLineBuf[FTokStart..fTokStop-1]) then
fTokKind := tkSpecK
else if rkAsm in fCurrRange.rangeKinds then
fTokKind:=tkAsmbl;
exit; exit;
end; end;
@ -973,12 +963,6 @@ end;
function TSynD2Syn.GetTokenAttribute: TSynHighlighterAttributes; function TSynD2Syn.GetTokenAttribute: TSynHighlighterAttributes;
begin begin
result := fAttribLut[fTokKind]; result := fAttribLut[fTokKind];
if (rkAsm in fCurrRange.rangeKinds) then
if (fTokKind <> tkSymbl) then
if (fTokKind <> tkKeywd) then
if (fTokKind <> tkCommt) then
if (fTokKind <> tkDDocs) then
result := fAsblrAttrib;
end; end;
procedure TSynD2Syn.SetRange(Value: Pointer); procedure TSynD2Syn.SetRange(Value: Pointer);