SynEdit: Pas Highlighter, only highlight "Objc..." keywords in MacPas mode (or if mode is not yet set)

This commit is contained in:
Martin 2023-03-09 10:43:01 +01:00
parent 4aeb1eb0ff
commit 3c70c9ed4d

View File

@ -78,6 +78,7 @@ type
rsAtPropertyOrReadWrite, // very first word after property (name of the property) or after read write in property rsAtPropertyOrReadWrite, // very first word after property (name of the property) or after read write in property
rsInterface, rsInterface,
rsImplementation, // Program or Implementation rsImplementation, // Program or Implementation
rsCompilerModeSet, // there was an explicit {$mode ...
// we need to detect: type TFoo = procedure; // must not fold // we need to detect: type TFoo = procedure; // must not fold
// var foo: procedure; // must not fold // var foo: procedure; // must not fold
@ -1199,6 +1200,7 @@ begin
end end
else else
if (fRange * [rsAfterClass, rsInObjcProtocol] = [rsAfterClass, rsInObjcProtocol]) and if (fRange * [rsAfterClass, rsInObjcProtocol] = [rsAfterClass, rsInObjcProtocol]) and
((CompilerMode = pcmMacPas) or not (rsCompilerModeSet in fRange)) and
KeyComp('name') and KeyComp('name') and
(PasCodeFoldRange.BracketNestLevel = 0) and (PasCodeFoldRange.BracketNestLevel = 0) and
(TopPascalCodeFoldBlockType in [cfbtClass]) (TopPascalCodeFoldBlockType in [cfbtClass])
@ -1791,7 +1793,9 @@ begin
if not (rsAfterClassMembers in fRange) then if not (rsAfterClassMembers in fRange) then
Result := tkIdentifier; Result := tkIdentifier;
end end
else if KeyComp('ObjcClass') then begin else if ((CompilerMode = pcmMacPas) or not (rsCompilerModeSet in fRange)) and
KeyComp('ObjcClass')
then begin
Result := tkKey; Result := tkKey;
if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
begin begin
@ -2250,12 +2254,13 @@ end;
function TSynPasSyn.Func124: TtkTokenKind; function TSynPasSyn.Func124: TtkTokenKind;
begin begin
if KeyComp('ObjcCategory') then if ((CompilerMode = pcmMacPas) or not (rsCompilerModeSet in fRange)) and
begin KeyComp('ObjcCategory')
then begin
Result := tkKey; Result := tkKey;
if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
begin begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass] - [rsVarTypeInSpecification, rsAfterEqual];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
end; end;
end end
@ -2432,8 +2437,9 @@ end;
function TSynPasSyn.Func144: TtkTokenKind; function TSynPasSyn.Func144: TtkTokenKind;
begin begin
if KeyComp('ObjcProtocol') then if ((CompilerMode = pcmMacPas) or not (rsCompilerModeSet in fRange)) and
begin KeyComp('ObjcProtocol')
then begin
Result := tkKey; Result := tkKey;
if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
begin begin
@ -2891,6 +2897,7 @@ begin
if TextComp('mode') then begin if TextComp('mode') then begin
// $mode directive // $mode directive
inc(Run,4); inc(Run,4);
include(fRange, rsCompilerModeSet);
// skip space // skip space
while (fLine[Run] in [' ',#9,#10,#13]) do inc(Run); while (fLine[Run] in [' ',#9,#10,#13]) do inc(Run);
if TextComp('objfpc') then if TextComp('objfpc') then
@ -2904,7 +2911,9 @@ begin
else if TextComp('tp') then else if TextComp('tp') then
CompilerMode:=pcmTP CompilerMode:=pcmTP
else if TextComp('macpas') then else if TextComp('macpas') then
CompilerMode:=pcmMacPas; CompilerMode:=pcmMacPas
else
exclude(fRange, rsCompilerModeSet);
end; end;
repeat repeat
case fLine[Run] of case fLine[Run] of