SynEdit: PasHighLighter, recognize TFoo = type class|object|record

This commit is contained in:
Martin 2023-12-19 20:09:17 +01:00
parent 3d48d3f0e6
commit 3d0e418a24
2 changed files with 22 additions and 12 deletions

View File

@ -1601,7 +1601,7 @@ function TSynPasSyn.Func55: TtkTokenKind;
begin begin
if KeyComp('Object') then begin if KeyComp('Object') then begin
Result := tkKey; Result := tkKey;
if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) if (fRange * [rsAfterEqualOrColon, rsAfterEqualThenType] <> []) and (PasCodeFoldRange.BracketNestLevel = 0)
then begin then begin
fRange := fRange + [rsAtClass] - [rsVarTypeInSpecification, rsAfterEqual]; fRange := fRange + [rsAtClass] - [rsVarTypeInSpecification, rsAfterEqual];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);

View File

@ -1462,11 +1462,12 @@ end;
procedure TTestHighlighterPas.TestContextForClassSection; procedure TTestHighlighterPas.TestContextForClassSection;
var var
rc, lead1, lead2, cm, s1, s2, v: string; ty, rc, lead1, lead2, cm, s1, s2, v: string;
strict1, strict2: Boolean; strict1, strict2: Boolean;
cmod, sp1, sp2: Integer; cmod, sp1, sp2: Integer;
begin begin
for rc in ['class ', 'object'] do for ty in [' ', 'type '] do
for rc in ['class ', 'object', 'record'] do
for lead1 in ['', ' '] do for lead1 in ['', ' '] do
for lead2 in ['', ' '] do for lead2 in ['', ' '] do
for cm in [' ', ' sealed abstract', ' sealed ', ' abstract '] do for cm in [' ', ' sealed abstract', ' sealed ', ' abstract '] do
@ -1484,9 +1485,9 @@ begin
cmod := 0; cmod := 0;
if cm[2] <> ' ' then if cm[2] <> ' ' then
case cm[9] of case cm[9] of
' ': cmod := 1; ' ': cmod := 1; // sealed
'a': cmod := 2; 'a': cmod := 2; // sealed abstract
't': cmod := 1; 't': cmod := 1; // abstract
end; end;
if (rc <> 'class ') and ( (cmod <> 0) or strict1 or strict2 ) if (rc <> 'class ') and ( (cmod <> 0) or strict1 or strict2 )
@ -1495,9 +1496,9 @@ begin
ReCreateEdit; ReCreateEdit;
SetLines SetLines
([ 'Unit A; interface', // 0 ([ 'Unit A; interface {$modeswitch advancedrecords}', // 0
'type', 'type',
'TFoo='+rc+cm , // 2 class sealed abstract 'TFoo='+ty+rc+cm , // 2 class sealed abstract
lead1+trim(s1), lead1+trim(s1),
lead2+trim(s2), lead2+trim(s2),
'a,'+trim(v)+':'+trim(v)+';', // 5 'a,'+trim(v)+':'+trim(v)+';', // 5
@ -1515,10 +1516,19 @@ begin
'' ''
]); ]);
case cmod of if ty[1] = ' ' then begin
0: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkKey ]); case cmod of
1: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkKey, tkSpace, tkKey, tkSpace ]); 0: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkSpace, tkKey ]);
2: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkKey, tkSpace, tkKey, tkSpace, tkKey ]); 1: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkSpace, tkKey, tkSpace, tkKey, tkSpace ]);
2: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkSpace, tkKey, tkSpace, tkKey, tkSpace, tkKey ]);
end;
end
else begin
case cmod of
0: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkKey, tkSpace, tkKey ]);
1: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkKey, tkSpace, tkKey, tkSpace, tkKey, tkSpace ]);
2: CheckTokensForLine('TFoo=class', 2, [ tkIdentifier, tkSymbol, tkKey, tkSpace, tkKey, tkSpace, tkKey, tkSpace, tkKey ]);
end;
end; end;
case strict1 of case strict1 of