SynEdit: PascalHighlighter, added "cvar", fixed "public","external" for variables.

- Moved some enum from range-state to token-state. (avoid changing the storage for ranges / limited to 32 entries)
This commit is contained in:
Martin 2024-01-24 22:17:51 +01:00
parent b3ee25c175
commit 0ce675d692
2 changed files with 444 additions and 54 deletions

View File

@ -98,9 +98,6 @@ type
rsAfterIdentifierOrValueAdd,
rsAtCaseLabel,
rsAtProcName, // after a procedure/function/... keyword, when the name is expected (not for types)
// also after "unit unitname" to detect "deprecated"
rsAfterProcName,
rsInProcHeader, // Declaration or implementation header of a Procedure, function, constructor...
rsWasInProcHeader, // after the semicolon that ended a "ProcHeader / proc-modifiers are possible
rsAfterClassMembers, // Encountered a procedure, function, property, constructor or destructor in a class
@ -108,7 +105,8 @@ type
rsVarTypeInSpecification, // between ":"/"=" and ";" in a var or type section (or class members)
// var a: Integer; type b = Int64;
rsInTypeBlock,
rsAfterEqualThenType, // TFoo = type ...
rsInConstBlock,
rsInTypedConst,
rsSkipAllPasBlocks // used for: class of ... ;
);
TRangeStates = set of TRangeState;
@ -117,11 +115,26 @@ type
// Except, will be kept for: tkSpace, tkComment, tkIDEDirective, tkDirective, tkNull // maybe in future line break
TTokenState = (
tsNone,
tsAfterExternal, // after public or external: "name" may follow
// procedure Foo; public name 'bar';
// procedure Foo; external 'x' name 'bar';
// var Foo; public name 'bar';
tsAfterAbsolute //var x absolute y;
tsAtProcName, // procedure ___
// unit ____ // used for "deprecated" detection / check in tsAfterProcName
// >>> after a procedure/function/... keyword, when the name is expected (not for types)
// >>> renewed after dot "."
tsAfterProcName, // procedure NAME
// unit NAME // used for "deprecated" detection
tsAfterEqualThenType, // TFoo = type
// >>> ONLY if type-helper enabled
tsAfterAbsolute, // var x absolute y;
tsAfterExternal, // procedure Foo; public name 'bar';
// procedure Foo; external 'x' name 'bar';
// var Foo; public name 'bar';
// after public, export or external: "name" may follow
// >>> KEPT until ONE AFTER the ";" => to prevent next token from being mistaken
// >>> Also SET BY "var"/"type"/"const" => to prevent next token from being mistaken
tsAfterCvar, // cvar;
// >>> KEPT until ONE AFTER the ";" => to prevent next token from being mistaken
tsAfterTypedConst // const foo: ___=___; public;
// >>> typed const can have modifiers
// Set AFTER ";"
);
type
@ -1194,8 +1207,9 @@ begin
tfb := TopPascalCodeFoldBlockType;
until not (tfb in [cfbtRecordCase, cfbtRecordCaseSection]);
fRange := fRange - [rsAtCaseLabel];
if TopPascalCodeFoldBlockType = cfbtRecord then
if TopPascalCodeFoldBlockType = cfbtRecord then begin
EndPascalCodeFoldBlock;
end;
// After type declaration, allow "deprecated"?
if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType,
cfbtClass, cfbtClassSection, cfbtRecord, cfbtRecordCase, cfbtRecordCaseSection]
@ -1210,6 +1224,9 @@ begin
cfbtClass, cfbtClassSection, cfbtRecord, cfbtRecordCase, cfbtRecordCaseSection]
then
fRange := fRange + [rsVarTypeInSpecification];
if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType, cfbtClass, cfbtClassSection, cfbtRecord]
then
fRange := fRange + [rsInTypeBlock];
end else if tfb = cfbtUnit then begin
EndPascalCodeFoldBlock;
end else if tfb = cfbtPackage then begin
@ -1271,6 +1288,9 @@ begin
cfbtClass, cfbtClassSection, cfbtRecord, cfbtRecordCase, cfbtRecordCaseSection]
then
fRange := fRange + [rsVarTypeInSpecification];
if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType, cfbtClass, cfbtClassSection, cfbtRecord]
then
fRange := fRange + [rsInTypeBlock];
end;
end else begin
Result := tkKey; // @@end or @end label
@ -1398,13 +1418,13 @@ begin
end
else
if (FTokenState = tsAfterExternal) and
// (PasCodeFoldRange.BracketNestLevel = 0) and
// (fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsWasInProcHeader]) and
// (TopPascalCodeFoldBlockType in ProcModifierAllowed) and
(PasCodeFoldRange.BracketNestLevel = 0) and
(fRange * [rsAfterSemiColon, rsAfterEqualOrColon, rsAfterEqual] = []) and
KeyComp('name') // procedure foo; public name 'abc';
then
begin
Result := tkKey;
FNextTokenState := tsAfterExternal; // external 'foo' name 'bar'
end
else
Result := tkIdentifier;
@ -1538,6 +1558,7 @@ begin
end;
fRange := fRange + [rsAfterSemiColon];
FOldRange := FOldRange - [rsAfterSemiColon];
FNextTokenState := tsAfterExternal; // prevent a variable of name public/export/external to be highlighted
end;
Result := tkKey;
end
@ -1573,6 +1594,19 @@ begin
Result := tkKey;
StartPascalCodeFoldBlock(cfbtPackage);
end
else
if (PasCodeFoldRange.BracketNestLevel = 0) and
( (FTokenState = tsAfterTypedConst) or
( not(FTokenState in [tsAfterExternal, tsAfterCvar]) and
(fRange * [rsAfterSemiColon, rsInProcHeader, rsWasInProcHeader, rsInTypeBlock, rsInConstBlock] = [rsAfterSemiColon])
) )
and
KeyComp('CVAR') and
(TopPascalCodeFoldBlockType() in [cfbtVarType, cfbtLocalVarType])
then begin
Result := tkKey;
FNextTokenState := tsAfterCvar;
end
else
Result := tkIdentifier;
end;
@ -1757,8 +1791,10 @@ begin
fRange := fRange + [rsAtPropertyOrReadWrite] - [rsVarTypeInSpecification];
end
else
if KeyComp('Generic') then
Result := tkKey
if KeyComp('Generic') then begin
Result := tkKey;
fRange := fRange + [rsInTypeBlock]; // in case it was incorrectly removed
end
else
Result := tkIdentifier;
end;
@ -1783,8 +1819,16 @@ begin
else
// outside class: procedure foo; public name 'abc';
if (PasCodeFoldRange.BracketNestLevel = 0) and
(fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsWasInProcHeader]) and
(tbf in ProcModifierAllowed - [cfbtClass, cfbtClassSection, cfbtRecord])
( (FTokenState in [tsAfterTypedConst, tsAfterCvar])
or
( (FTokenState <> tsAfterExternal) and
( ( (fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsWasInProcHeader]) and
(tbf in ProcModifierAllowed - [cfbtClass, cfbtClassSection, cfbtRecord])
) or
( (fRange * [rsAfterSemiColon, rsInProcHeader, rsWasInProcHeader, rsInTypeBlock, rsInConstBlock] = [rsAfterSemiColon]) and
(tbf in [cfbtVarType, cfbtLocalVarType])
) ) )
)
then begin
Result := tkKey;
FNextTokenState := tsAfterExternal;
@ -1824,7 +1868,7 @@ begin
if KeyComp('Unit') then begin
if TopPascalCodeFoldBlockType=cfbtNone then StartPascalCodeFoldBlock(cfbtUnit);
Result := tkKey;
fRange := fRange + [rsAtProcName];
FNextTokenState := tsAtProcName;
end
else if KeyComp('Uses') then begin
if (TopPascalCodeFoldBlockType in
@ -1841,7 +1885,7 @@ begin
fRange := fRange - [rsVarTypeInSpecification, rsAfterEqual] + [rsInTypeHelper];
end
else
if (rsAfterEqualThenType in fRange) and TypeHelpers then begin
if (FTokenState = tsAfterEqualThenType) and TypeHelpers then begin
Result := tkKey;
fRange := fRange - [rsVarTypeInSpecification, rsAfterEqual] + [rsInTypeHelper];
StartPascalCodeFoldBlock(cfbtClass); // type helper
@ -1877,7 +1921,7 @@ begin
if (rsAfterEqualOrColon in fRange) then begin
FOldRange := FOldRange - [rsAfterEqualOrColon];
if TypeHelpers then
fRange := fRange + [rsAfterEqualThenType];
FNextTokenState := tsAfterEqualThenType;
end
else begin
if tfb in [cfbtVarType, cfbtLocalVarType] then begin
@ -1890,6 +1934,7 @@ begin
else StartPascalCodeFoldBlock(cfbtVarType);
fRange := fRange + [rsInTypeBlock, rsAfterSemiColon];
FOldRange := FOldRange - [rsAfterSemiColon];
FNextTokenState := tsAfterExternal; // prevent a type of name public/export/external to be highlighted
end;
end;
Result := tkKey;
@ -1956,8 +2001,9 @@ begin
then StartPascalCodeFoldBlock(cfbtLocalVarType)
else StartPascalCodeFoldBlock(cfbtVarType);
end;
fRange := fRange + [rsAfterSemiColon];
fRange := fRange + [rsAfterSemiColon, rsInConstBlock];
FOldRange := FOldRange - [rsAfterSemiColon];
FNextTokenState := tsAfterExternal; // prevent a variable of name public/export/external to be highlighted
end;
Result := tkKey;
end
@ -2066,6 +2112,7 @@ begin
else if KeyComp('Deprecated') then begin
tbf := TopPascalCodeFoldBlockType;
if ( ( (tbf in [cfbtVarType, cfbtLocalVarType]) and
(FTokenState <> tsAfterAbsolute) and
(fRange * [rsVarTypeInSpecification, rsAfterEqualOrColon] = [rsVarTypeInSpecification]) ) or
( (tbf in [cfbtClass, cfbtClassSection, cfbtRecord, cfbtRecordCase, cfbtRecordCaseSection]) and
( (fRange * [rsAfterClassMembers, rsInProcHeader] = [rsAfterClassMembers]) or
@ -2074,7 +2121,7 @@ begin
( (tbf in [cfbtUnitSection, cfbtProgram, cfbtProcedure]) and
(fRange * [rsInProcHeader] = []) ) or
( (tbf in [cfbtUnit, cfbtNone]) and
(fRange * [rsInProcHeader, rsAfterProcName] = [rsAfterProcName]) )
(fRange * [rsInProcHeader] = []) and (FTokenState = tsAfterProcName) )
) and
( fRange *[rsAfterEqualOrColon, rsProperty] = [] ) and
(PasCodeFoldRange.BracketNestLevel = 0)
@ -2342,13 +2389,23 @@ begin
end;
function TSynPasSyn.Func98: TtkTokenKind;
var
tbf: TPascalCodeFoldBlockType;
begin
tbf := TopPascalCodeFoldBlockType;
if (PasCodeFoldRange.BracketNestLevel in [0, 1]) and
(fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsWasInProcHeader]) and
(TopPascalCodeFoldBlockType in ProcModifierAllowed) and
(FTokenState <> tsAfterExternal) and
( ( (fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsWasInProcHeader]) and
(tbf in ProcModifierAllowed)
) or
( (fRange * [rsAfterSemiColon, rsInProcHeader, rsWasInProcHeader, rsInTypeBlock, rsInConstBlock] = [rsAfterSemiColon]) and
(tbf in [cfbtVarType, cfbtLocalVarType])
)
) and
KeyComp('Export')
then begin
Result := tkKey;
FNextTokenState := tsAfterExternal;
end
else
if KeyComp('Nodefault') then
@ -2363,8 +2420,13 @@ var
begin
tbf := TopPascalCodeFoldBlockType;
if (PasCodeFoldRange.BracketNestLevel = 0) and
( (fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsWasInProcHeader]) and
(tbf in ProcModifierAllowed)
(FTokenState <> tsAfterExternal) and
( ( (fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsWasInProcHeader]) and
(tbf in ProcModifierAllowed)
) or
( (fRange * [rsAfterSemiColon, rsInProcHeader, rsWasInProcHeader, rsInTypeBlock, rsInConstBlock] = [rsAfterSemiColon]) and
(tbf in [cfbtVarType, cfbtLocalVarType])
)
) and
KeyComp('External')
then begin
@ -2406,6 +2468,7 @@ begin
if KeyComp('Platform') then begin
tbf := TopPascalCodeFoldBlockType;
if ( ( (tbf in [cfbtVarType, cfbtLocalVarType]) and
(FTokenState <> tsAfterAbsolute) and
(fRange * [rsVarTypeInSpecification, rsAfterEqualOrColon] = [rsVarTypeInSpecification]) ) or
( (tbf in [cfbtClass, cfbtClassSection, cfbtRecord, cfbtRecordCase, cfbtRecordCaseSection]) and
( (fRange * [rsAfterClassMembers, rsInProcHeader] = [rsAfterClassMembers]) or
@ -2414,7 +2477,7 @@ begin
( (tbf in [cfbtUnitSection, cfbtProgram, cfbtProcedure]) and
(fRange * [rsInProcHeader] = []) ) or
( (tbf in [cfbtUnit, cfbtNone]) and
(fRange * [rsInProcHeader, rsAfterProcName] = [rsAfterProcName]) )
(fRange * [rsInProcHeader] = []) and (FTokenState = tsAfterProcName) )
) and
( fRange *[rsAfterEqualOrColon, rsProperty] = [] ) and
(PasCodeFoldRange.BracketNestLevel = 0)
@ -2451,7 +2514,7 @@ begin
if InClass then
fRange := fRange + [rsAfterClassMembers];
fRange := fRange + [rsAtProcName];
FNextTokenState := tsAtProcName;
end;
end;
fRange := fRange + [rsInProcHeader];
@ -2505,7 +2568,7 @@ begin
if InClass then
fRange := fRange + [rsAfterClassMembers];
fRange := fRange + [rsAtProcName];
FNextTokenState := tsAtProcName;
end;
end;
fRange := fRange + [rsInProcHeader];
@ -2558,7 +2621,7 @@ begin
if InClass then
fRange := fRange + [rsAfterClassMembers];
//fRange := fRange + [rsAtProcName];
//FNextTokenState := tsAtProcName;
end;
fRange := fRange + [rsInProcHeader];
Result := tkKey;
@ -2762,6 +2825,7 @@ begin
if KeyComp('Experimental') then begin
tbf := TopPascalCodeFoldBlockType;
if ( ( (tbf in [cfbtVarType, cfbtLocalVarType]) and
(FTokenState <> tsAfterAbsolute) and
(fRange * [rsVarTypeInSpecification, rsAfterEqualOrColon] = [rsVarTypeInSpecification]) ) or
( (tbf in [cfbtClass, cfbtClassSection, cfbtRecord, cfbtRecordCase, cfbtRecordCaseSection]) and
( (fRange * [rsAfterClassMembers, rsInProcHeader] = [rsAfterClassMembers]) or
@ -2770,7 +2834,7 @@ begin
( (tbf in [cfbtUnitSection, cfbtProgram, cfbtProcedure]) and
(fRange * [rsInProcHeader] = []) ) or
( (tbf in [cfbtUnit, cfbtNone]) and
(fRange * [rsInProcHeader, rsAfterProcName] = [rsAfterProcName]) )
(fRange * [rsInProcHeader] = []) and (FTokenState = tsAfterProcName) )
) and
( fRange *[rsAfterEqualOrColon, rsProperty] = [] ) and
(PasCodeFoldRange.BracketNestLevel = 0)
@ -2803,7 +2867,8 @@ begin
if InClass then
fRange := fRange + [rsAfterClassMembers];
fRange := fRange + [rsInProcHeader, rsAtProcName];
fRange := fRange + [rsInProcHeader];
FNextTokenState := tsAtProcName;
end;
Result := tkKey;
end else
@ -2842,6 +2907,7 @@ begin
tbf := TopPascalCodeFoldBlockType;
if KeyComp('Unimplemented') then begin
if ( ( (tbf in [cfbtVarType, cfbtLocalVarType]) and
(FTokenState <> tsAfterAbsolute) and
(fRange * [rsVarTypeInSpecification, rsAfterEqualOrColon] = [rsVarTypeInSpecification]) ) or
( (tbf in [cfbtClass, cfbtClassSection, cfbtRecord, cfbtRecordCase, cfbtRecordCaseSection]) and
( (fRange * [rsAfterClassMembers, rsInProcHeader] = [rsAfterClassMembers]) or
@ -2850,7 +2916,7 @@ begin
( (tbf in [cfbtUnitSection, cfbtProgram, cfbtProcedure]) and
(fRange * [rsInProcHeader] = []) ) or
( (tbf in [cfbtUnit, cfbtNone]) and
(fRange * [rsInProcHeader, rsAfterProcName] = [rsAfterProcName]) )
(fRange * [rsInProcHeader] = []) and (FTokenState = tsAfterProcName) )
) and
( fRange *[rsAfterEqualOrColon, rsProperty] = [] ) and
(PasCodeFoldRange.BracketNestLevel = 0)
@ -2889,7 +2955,8 @@ begin
if InClass then
fRange := fRange + [rsAfterClassMembers];
fRange := fRange + [rsInProcHeader, rsAtProcName];
fRange := fRange + [rsInProcHeader];
FNextTokenState := tsAtProcName;
end;
Result := tkKey;
end else
@ -3559,11 +3626,15 @@ begin
fRange := fRange + [rsVarTypeInSpecification];
// modifiers "alias: 'foo';"
if (PasCodeFoldRange.BracketNestLevel = 0) and
(fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsInProcHeader]) and
(TopPascalCodeFoldBlockType in ProcModifierAllowed)
then
FRange := FRange + [rsInProcHeader];
if (PasCodeFoldRange.BracketNestLevel = 0) then begin
if (fRange * [rsInProcHeader, rsProperty, rsAfterEqualOrColon, rsWasInProcHeader] = [rsInProcHeader]) and
(TopPascalCodeFoldBlockType in ProcModifierAllowed)
then
FRange := FRange + [rsInProcHeader]
else
if rsInConstBlock in fRange then
fRange := fRange + [rsInTypedConst];
end;
end;
end;
@ -3720,10 +3791,10 @@ begin
fRange := fRange + [rsAtPropertyOrReadWrite];
FOldRange := FOldRange - [rsAtPropertyOrReadWrite];
end;
if fRange * [rsAfterProcName] = [rsAfterProcName] then begin
if (FTokenState = tsAfterProcName) then begin
if rsInProcHeader in fRange then
FTokenFlags := FTokenFlags + [tfProcName];
fRange := fRange + [rsAtProcName];
FNextTokenState := tsAtProcName;
end;
end;
@ -3917,7 +3988,14 @@ begin
fRange := fRange + [rsWasInProcHeader];
fRange := fRange - [rsProperty, rsInProcHeader];
end;
fRange := fRange - [rsVarTypeInSpecification, rsAfterEqual] + [rsAfterSemiColon];
if FTokenState in [tsAfterExternal, tsAfterCvar] then
FNextTokenState := FTokenState
else
if rsInTypedConst in fRange then
FNextTokenState := tsAfterTypedConst;
fRange := fRange - [rsVarTypeInSpecification, rsAfterEqual, rsInTypedConst] + [rsAfterSemiColon];
FOldRange := FOldRange - [rsAfterSemiColon];
end;
@ -4123,15 +4201,15 @@ begin
fProcTable[fLine[Run]];
if not (FTokenID in [tkSpace, tkComment, tkIDEDirective, tkDirective, tkNull]) then
FTokenState := FNextTokenState;
if (FTokenID = tkIdentifier) and (fRange * [rsAtProcName] = [rsAtProcName]) then begin
if (FTokenID = tkIdentifier) and (FTokenState = tsAtProcName) then begin
if rsInProcHeader in fRange then
FTokenFlags := FTokenFlags + [tfProcName];
fRange := fRange + [rsAfterProcName];
FNextTokenState := tsAfterProcName;
end;
if not (FTokenID in [tkSpace, tkComment, tkIDEDirective, tkDirective, tkNull]) then
FTokenState := FNextTokenState;
if (IsAtCaseLabel) and (rsAtCaseLabel in fRange) then begin
FTokenIsCaseLabel := True;
if (FTokenID = tkKey) then
@ -4151,8 +4229,7 @@ begin
fRange := fRange -
(FOldRange * [rsAfterEqualOrColon, rsAfterSemiColon,
rsAtPropertyOrReadWrite, rsAfterClassField,
rsAfterIdentifierOrValue, rsAfterEqualThenType,
rsWasInProcHeader, rsAtProcName, rsAfterProcName,
rsAfterIdentifierOrValue, rsWasInProcHeader,
rsInTypeHelper]
);
@ -5082,7 +5159,7 @@ begin
Exclude(fRange, rsSkipAllPasBlocks);
BlockType := TopPascalCodeFoldBlockType;
if BlockType in [cfbtVarType, cfbtLocalVarType] then
fRange := fRange - [rsInTypeBlock];
fRange := fRange - [rsInTypeBlock, rsInConstBlock];
fRange := fRange - [rsAfterEqual];
DecreaseLevel := TopCodeFoldBlockType < CountPascalCodeFoldBlockOffset;
// TODO: let inherited call CollectNodeInfo

View File

@ -59,6 +59,7 @@ type
procedure TestContextForProcModifiers;
procedure TestContextForProcModifiers2;
procedure TestContextForProcModifiersName;
procedure TestContextForVarModifiers;
procedure TestContextForProperties;
procedure TestContextForProcedure;
procedure TestContextForProcedureNameAttr;
@ -834,6 +835,313 @@ begin
end;
end;
procedure TTestHighlighterPas.TestContextForVarModifiers;
var
n: String;
AFolds: TPascalCodeFoldBlockTypes;
i, j: Integer;
begin
ReCreateEdit;
for i := 0 to 7 do begin
case i of
0: n := 'name';
1: n := 'public';
2: n := 'external';
3: n := 'export';
4: n := 'cvar';
5: n := 'deprecated';
6: n := 'default';
7: n := 'absolute';
end;
SetLines
([ 'Unit A; interface',
'',
'var ',
// Line 3:
n+':'+n+'; public;',
n+':'+n+'; public name ''name'';',
n+':'+n+'; external;',
n+':'+n+'; external ''name'';',
n+':'+n+'; external name ''name'';',
n+':'+n+'; external ''name'' name ''name'';',
n+':'+n+'; export;',
n+':'+n+'; export name ''name'';',
'',
'',
// Line 13:
n+':'+n+';cvar; public;',
n+':'+n+';cvar; public name ''name'';',
n+':'+n+';cvar; external;',
n+':'+n+';cvar; external ''name'';',
'',//n+':'+n+';cvar; external name ''name'';',
'',//n+':'+n+';cvar; external ''name'' name ''name'';',
n+':'+n+';cvar; export;',
n+':'+n+';cvar; export name ''name'';',
n+':'+n+';cvar; cvar: cvar; name: name; var', // just another variable
'',
// Line 23:
n+':'+n+'=1; public;',
n+':'+n+'=1; public name ''name'';',
'',//n+':'+n+'=1; external;',
'',//n+':'+n+'=1; external ''name'';',
'',//n+':'+n+'=1; external name ''name'';',
'',//n+':'+n+'=1; external ''name'' name ''name'';',
n+':'+n+'=1; export;',
n+':'+n+'=1; export name ''name'';',
'',
'',
// Line 33:
n+':'+n+' deprecated; public;',
n+':'+n+' deprecated; public name ''name'';',
n+':'+n+' deprecated; external;',
n+':'+n+' deprecated; external ''name'';',
n+':'+n+' deprecated; external name ''name'';',
n+':'+n+' deprecated; external ''name'' name ''name'';',
n+':'+n+' deprecated; export;',
n+':'+n+' deprecated; export name ''name'';',
'',
'',
// Line 43:
n+':'+n+' absolute '+n+';',
'',
'',
'',
'type',
// Line 48:
n+'='+n+'; '+n+'='+n+';', // just another type
'const',
// Line 50:
n+'='+n+'; '+n+'='+n+';', // just another const
n+':'+n+'='+n+'; cvar;', // key CVAR
n+':'+n+'='+n+'; cvar; public;', // key CVAR
n+':'+n+'='+n+'; public;', // key public
n+':'+n+'='+n+'; public name ''name'';', // key public name
'',
'',
'',
'',
// NOT for "public"
'type TFoo = class ',
// Line 60:
n+':'+n+'; '+n+':'+n+'; public private', // just another field
n+':'+n+'; public '+n+':'+n+'; public private', // just another public field
'var '+n+':'+n+'; public '+n+':'+n+'; public private', // just another public field
'type '+n+':'+n+'; '+n+':'+n+'; public private', // just another type
'const '+n+':'+n+'='+n+'; '+n+':'+n+'='+n+'; public private', // just another const
'',
'end;',
''
]);
for j := 0 to $1F do begin
AFolds := [];
if (j and $10) = 0 then AFolds := [cfbtBeginEnd..cfbtNone] - [cfbtUnitSection, cfbtVarType, cfbtClass, cfbtClassSection];
if (j and $01) = 0 then AFolds := AFolds + [cfbtUnitSection];
if (j and $02) = 0 then AFolds := AFolds + [cfbtVarType];
if (j and $04) = 0 then AFolds := AFolds + [cfbtClass];
if (j and $08) = 0 then AFolds := AFolds + [cfbtClassSection];
EnableFolds(AFolds);
CheckTokensForLine(n+':'+n+'; public;', 3,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+'; public name ''name'';', 4,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+'; external;', 5,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+'; external ''name'';', 6,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+'; external name ''name'';', 7,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+'; external ''name'' name ''name'';', 8,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, tkSpace, tkString, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+'; export;', 9,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+'; export name ''name'';', 10,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+';cvar; public;', 13,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkKey {cvar}, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+';cvar; public name ''name'';', 14,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkKey {cvar}, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+';cvar; external;', 15,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkKey {cvar}, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+';cvar; external ''name'';', 16,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkKey {cvar}, TK_Semi, tkSpace,
tkKey, tkSpace, tkString, TK_Semi
]);
// CheckTokensForLine(n+':'+n+';cvar; external name ''name'';', 17,
// tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
// [tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace, tkKey {cvar}, TK_Semi, tkSpace,
// ]);
// CheckTokensForLine(n+':'+n+';cvar; external ''name'' name ''name'';', 18,
// [tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace, tkKey {cvar}, TK_Semi, tkSpace,
// tkKey, tkSpace, tkString, tkSpace, tkKey, tkSpace, tkString, TK_Semi
// ]);
CheckTokensForLine(n+':'+n+';cvar; export;', 19,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkKey {cvar}, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+';cvar; export name ''name'';', 20,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkKey {cvar}, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
// just another var:
CheckTokensForLine(n+':'+n+';cvar; cvar: cvar; name: name; var', 21,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkKey {cvar}, TK_Semi, tkSpace,
tkIdentifier, TK_Colon, tkSpace, tkIdentifier, TK_Semi, tkSpace,
tkIdentifier, TK_Colon, tkSpace, tkIdentifier, TK_Semi,
tkSpace, tkKey
]);
CheckTokensForLine(n+':'+n+'=1; public;', 23,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+'=1; public name ''name'';', 24,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
// CheckTokensForLine(n+':'+n+'=1; external;', 25,
// [tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
// tkKey, TK_Semi
// ]);
// CheckTokensForLine(n+':'+n+'=1; external ''name'';', 26,
// [tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
// tkKey, tkSpace, tkString, TK_Semi
// ]);
// CheckTokensForLine(n+':'+n+'=1; external name ''name'';', 27,
// [tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
// tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
// ]);
// CheckTokensForLine(n+':'+n+'=1; external ''name'' name ''name'';', 28,
// [tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
// tkKey, tkSpace, tkString, tkSpace, tkKey, tkSpace, tkString, TK_Semi
// ]);
CheckTokensForLine(n+':'+n+'=1; export;', 29,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+'=1; export name ''name'';', 30,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkNumber, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; public;', 33,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; public name ''name'';', 34,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; external;', 35,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; external ''name'';', 36,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; external name ''name'';', 37,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; external ''name'' name ''name'';', 38,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, tkSpace, tkString, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; export;', 39,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+' deprecated; export name ''name'';', 40,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{depr}, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
CheckTokensForLine(n+':'+n+' absolute '+n+';', 43,
[tkIdentifier, TK_Colon, tkIdentifier, tkSpace, tkKey{absolute}, tkSpace, tkIdentifier, TK_Semi ]);
//TYPE / just another type
CheckTokensForLine(n+'='+n+'; '+n+'='+n+';', 48,
[tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkIdentifier, TK_Equal, tkIdentifier, TK_Semi]);
// const
CheckTokensForLine(n+'='+n+'; '+n+'='+n+';', 50, // just another const
[tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkIdentifier, TK_Equal, tkIdentifier, TK_Semi]);
CheckTokensForLine(n+':'+n+'='+n+'; cvar;', 51, // key CVAR
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
if copy(n,1,6) = 'public' then
continue;
// NOT for "public"
CheckTokensForLine(n+':'+n+'='+n+'; cvar; public;', 52, // key CVAR
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkKey, TK_Semi, tkSpace, tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+'='+n+'; public;', 53, // key public
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkKey, TK_Semi
]);
CheckTokensForLine(n+':'+n+'='+n+'; public name ''name'';', 54, // key public name
[tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkKey, tkSpace, tkKey, tkSpace, tkString, TK_Semi
]);
// NOT for "public"
CheckTokensForLine('#CLASS#'+ n+':'+n+'; '+n+':'+n+'; public private', 60,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace,
tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace, tkKey {public}, tkSpace, tkKey {private}
]);
CheckTokensForLine('#CLASS#'+n+':'+n+'; public '+n+':'+n+'; public private', 61,
[tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace, tkKey {public}, tkSpace,
tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace, tkKey {public}, tkSpace, tkKey {private}
]);
CheckTokensForLine('#CLASS#'+'var '+n+':'+n+'; public '+n+':'+n+'; public private', 62,
[tkKey{var}, tkSpace,
tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace, tkKey {public}, tkSpace,
tkIdentifier, TK_Colon, tkIdentifier, TK_Semi, tkSpace, tkKey {public}, tkSpace, tkKey {private}
]);
CheckTokensForLine('#CLASS#'+'type '+n+'='+n+'; '+n+'='+n+'; public private', 63,
[tkKey{type}, tkSpace,
tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace, tkKey {public}, tkSpace, tkKey {private}]);
CheckTokensForLine('#CLASS#'+'const '+n+':'+n+'='+n+'; '+n+':'+n+'='+n+'; public private', 64, // just another const
[tkKey{const}, tkSpace,
tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace,
tkIdentifier, TK_Colon, tkIdentifier, TK_Equal, tkIdentifier, TK_Semi, tkSpace, tkKey {public}, tkSpace, tkKey {private}]);
end;
end;
end;
procedure TTestHighlighterPas.TestContextForProperties;
var
AFolds: TPascalCodeFoldBlockTypes;
@ -1549,6 +1857,7 @@ procedure TTestHighlighterPas.TestContextForDeprecated;
'foo, '+s+', bar: Integer '+s+';',
'type',
s+' = '+s+' '+s+';', // nameDEPRECATED = typeDEPRECATED deprecated;
s+' =type '+s+' '+s+';', // nameDEPRECATED = type typeDEPRECATED deprecated;
'procedure '+s+'('+s+': '+s+'); '+s+';',
'var',
s+':procedure '+s+';',
@ -1561,11 +1870,13 @@ procedure TTestHighlighterPas.TestContextForDeprecated;
tkSpace, tkIdentifier, tkSpace, tkKey {the one and only}, tkSymbol]);
CheckTokensForLine('type', 5,
[tkIdentifier, tkSpace, tkSymbol, tkSpace, tkIdentifier, tkSpace, tkKey {the one and only}, tkSymbol]);
CheckTokensForLine('procedure', 6,
CheckTokensForLine('type', 6,
[tkIdentifier, tkSpace, tkSymbol, tkKey, tkSpace, tkIdentifier, tkSpace, tkKey {the one and only}, tkSymbol]);
CheckTokensForLine('procedure', 7,
[tkKey, tkSpace, tkIdentifier + FAttrProcName, tkSymbol { ( }, tkIdentifier, tkSymbol { : },
tkSpace, tkIdentifier, tkSymbol { ) }, tkSymbol, tkSpace, tkKey {the one and only}, tkSymbol
]);
CheckTokensForLine('var a:procedure DEPRECATED;', 8,
CheckTokensForLine('var a:procedure DEPRECATED;', 9,
[tkIdentifier, TK_Colon, tkKey, tkSpace, tkKey {the one and only}, TK_Semi]);
@ -1910,8 +2221,10 @@ begin
CheckTokensForLine('public:public;', 15,
[ sp1, tkIdentifier {public}, tkSymbol{:}, tkIdentifier, tkSymbol{;} ]);
CheckTokensForLine('public:public;', 16,
[ sp2, tkIdentifier {public}, tkSymbol{:}, tkIdentifier, tkSymbol{;} ]);
// public would be modifier
if trim(v) <> 'public' then
CheckTokensForLine('public:public;', 16,
[ sp2, tkIdentifier {public}, tkSymbol{:}, tkIdentifier, tkSymbol{;} ]);
end;
end;