SynEdit: Pas-HL, fixed wrong folding of "var a: procedure;"

git-svn-id: trunk@27958 -
This commit is contained in:
martin 2010-10-29 22:26:34 +00:00
parent dc0bf4916d
commit cc55a41750

View File

@ -68,17 +68,19 @@ type
TRangeState = ( TRangeState = (
// rsAnsi, rsBor, rsDirective are exclusive to each other // rsAnsi, rsBor, rsDirective are exclusive to each other
rsAnsi, // *) comment rsAnsi, // *) comment
rsBor, // { comment rsBor, // { comment
rsSlash, // // rsSlash, // //
rsDirective, rsDirective,
rsAsm, // assembler block rsAsm, // assembler block
rsProperty, rsProperty,
rsInterface, rsInterface,
rsImplementation, // Program or Implementation rsImplementation, // Program or Implementation
// we need to detect if procedure is a "type x = procedure" // we need to detect
rsAtEqual, // "=" either in compare or in type/const assign // type Tfoo = procedure; // must not fold
rsAfterEqual, // vare foo: procedure; // must not fold
//rsAtEqual, // "=" either in compare or in type/const assign
rsAfterEqualOrColon, // very first word after "=" or ":"
// Detect if class/object is ended by ";" or "end;" // Detect if class/object is ended by ";" or "end;"
rsAtClass, rsAtClass,
rsAfterClass, rsAfterClass,
@ -1145,7 +1147,7 @@ function TSynPasSyn.Func54: TtkTokenKind;
begin begin
if KeyComp('Class') then begin if KeyComp('Class') then begin
Result := tkKey; Result := tkKey;
if (rsAfterEqual in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0)
then begin then begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
@ -1158,7 +1160,7 @@ function TSynPasSyn.Func55: TtkTokenKind;
begin begin
if KeyComp('Object') then begin if KeyComp('Object') then begin
Result := tkKey; Result := tkKey;
if (rsAfterEqual in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0)
then begin then begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
@ -1263,7 +1265,7 @@ begin
if (PasCodeFoldRange.BracketNestLevel = 0) if (PasCodeFoldRange.BracketNestLevel = 0)
and (TopPascalCodeFoldBlockType in and (TopPascalCodeFoldBlockType in
[cfbtVarType, cfbtLocalVarType, cfbtNone, cfbtProcedure, cfbtProgram, [cfbtVarType, cfbtLocalVarType, cfbtNone, cfbtProcedure, cfbtProgram,
cfbtUnit, cfbtUnitSection]) and not(rsAfterEqual in fRange) cfbtUnit, cfbtUnitSection]) and not(rsAfterEqualOrColon in fRange)
then begin then begin
if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then
EndPascalCodeFoldBlockLastLine; EndPascalCodeFoldBlockLastLine;
@ -1375,13 +1377,13 @@ begin
if rsProperty in fRange then Result := tkKey else Result := tkIdentifier; if rsProperty in fRange then Result := tkKey else Result := tkIdentifier;
end else end else
if KeyComp('Interface') then begin if KeyComp('Interface') then begin
if (rsAfterEqual in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0)
then begin then begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
end end
else else
if not(rsAfterEqual in fRange) and if not(rsAfterEqualOrColon in fRange) and
(fRange * [rsInterface, rsImplementation] = []) then (fRange * [rsInterface, rsImplementation] = []) then
begin begin
CloseBeginEndBlocksBeforeProc; CloseBeginEndBlocksBeforeProc;
@ -1408,7 +1410,7 @@ begin
if KeyComp('ObjcClass') then if KeyComp('ObjcClass') then
begin begin
Result := tkKey; Result := tkKey;
if (rsAfterEqual in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
begin begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
@ -1528,7 +1530,7 @@ begin
if KeyComp('CppClass') then if KeyComp('CppClass') then
begin begin
Result := tkKey; Result := tkKey;
if (rsAfterEqual in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
begin begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
@ -1651,7 +1653,7 @@ end;
function TSynPasSyn.Func102: TtkTokenKind; function TSynPasSyn.Func102: TtkTokenKind;
begin begin
if KeyComp('Function') then begin if KeyComp('Function') then begin
if not(rsAfterEqual in fRange) then begin if not(rsAfterEqualOrColon in fRange) then begin
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
CloseBeginEndBlocksBeforeProc; CloseBeginEndBlocksBeforeProc;
if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then
@ -1675,7 +1677,7 @@ end;
function TSynPasSyn.Func105: TtkTokenKind; function TSynPasSyn.Func105: TtkTokenKind;
begin begin
if KeyComp('Procedure') then begin if KeyComp('Procedure') then begin
if not(rsAfterEqual in fRange) then begin if not(rsAfterEqualOrColon in fRange) then begin
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
CloseBeginEndBlocksBeforeProc; CloseBeginEndBlocksBeforeProc;
if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then
@ -1713,7 +1715,7 @@ function TSynPasSyn.Func108: TtkTokenKind;
begin begin
if KeyComp('Operator') then if KeyComp('Operator') then
begin begin
if not(rsAfterEqual in fRange) then if not(rsAfterEqualOrColon in fRange) then
begin begin
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
CloseBeginEndBlocksBeforeProc; CloseBeginEndBlocksBeforeProc;
@ -1765,7 +1767,7 @@ begin
if KeyComp('Dispinterface') then if KeyComp('Dispinterface') then
begin begin
Result := tkKey; Result := tkKey;
if (rsAfterEqual in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
begin begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
@ -1848,7 +1850,7 @@ function TSynPasSyn.Func143: TtkTokenKind;
begin begin
if KeyComp('Destructor') then if KeyComp('Destructor') then
begin begin
if not(rsAfterEqual in fRange) then if not(rsAfterEqualOrColon in fRange) then
begin begin
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
CloseBeginEndBlocksBeforeProc; CloseBeginEndBlocksBeforeProc;
@ -1873,7 +1875,7 @@ begin
if KeyComp('ObjcProtocol') then if KeyComp('ObjcProtocol') then
begin begin
Result := tkKey; Result := tkKey;
if (rsAfterEqual in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
begin begin
fRange := fRange + [rsAtClass]; fRange := fRange + [rsAtClass];
StartPascalCodeFoldBlock(cfbtClass); StartPascalCodeFoldBlock(cfbtClass);
@ -1894,7 +1896,7 @@ end;
function TSynPasSyn.Func166: TtkTokenKind; function TSynPasSyn.Func166: TtkTokenKind;
begin begin
if KeyComp('Constructor') then begin if KeyComp('Constructor') then begin
if not(rsAfterEqual in fRange) then begin if not(rsAfterEqualOrColon in fRange) then begin
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
CloseBeginEndBlocksBeforeProc; CloseBeginEndBlocksBeforeProc;
if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then if TopPascalCodeFoldBlockType in [cfbtVarType, cfbtLocalVarType] then
@ -2377,7 +2379,10 @@ procedure TSynPasSyn.ColonOrGreaterProc;
begin begin
fTokenID := tkSymbol; fTokenID := tkSymbol;
inc(Run); inc(Run);
if fLine[Run] = '=' then inc(Run); if fLine[Run] = '=' then
inc(Run)
else
fRange := fRange + [rsAfterEqualOrColon];
fRange := fRange - [rsAtCaseLabel]; fRange := fRange - [rsAtCaseLabel];
end; end;
@ -2597,7 +2602,7 @@ procedure TSynPasSyn.EqualSignProc;
begin begin
inc(Run); inc(Run);
fTokenID := tkSymbol; fTokenID := tkSymbol;
fRange := fRange + [rsAtEqual]; fRange := fRange + [rsAfterEqualOrColon];
end; end;
procedure TSynPasSyn.SemicolonProc; procedure TSynPasSyn.SemicolonProc;
@ -2720,6 +2725,7 @@ end;
procedure TSynPasSyn.Next; procedure TSynPasSyn.Next;
var var
IsAtCaseLabel: Boolean; IsAtCaseLabel: Boolean;
WasAtEqual: Boolean;
begin begin
fAsmStart := False; fAsmStart := False;
fTokenPos := Run; fTokenPos := Run;
@ -2742,9 +2748,10 @@ begin
else if rsSlash in fRange then else if rsSlash in fRange then
SlashContinueProc SlashContinueProc
else begin else begin
if rsAtEqual in fRange then WasAtEqual := rsAfterEqualOrColon in fRange;
fRange := fRange + [rsAfterEqual] - [rsAtEqual] //if rsAtEqual in fRange then
else // fRange := fRange + [rsAfterEqualOrColon] - [rsAtEqual]
//else
if rsAtClass in fRange then if rsAtClass in fRange then
fRange := fRange + [rsAfterClass] - [rsAtClass]; fRange := fRange + [rsAfterClass] - [rsAtClass];
IsAtCaseLabel := rsAtCaseLabel in fRange; IsAtCaseLabel := rsAtCaseLabel in fRange;
@ -2758,9 +2765,12 @@ begin
end; end;
if not (FTokenID in [tkSpace, tkComment, tkDirective]) then begin if not (FTokenID in [tkSpace, tkComment, tkDirective]) then begin
if (PasCodeFoldRange.BracketNestLevel = 0) and if (PasCodeFoldRange.BracketNestLevel = 0) and
not(rsAtClosingBracket in fRange) then not(rsAtClosingBracket in fRange)
then
fRange := fRange - [rsAfterClass]; fRange := fRange - [rsAfterClass];
fRange := fRange - [rsAfterEqual, rsAtClosingBracket]; if WasAtEqual then
fRange := fRange - [rsAfterEqualOrColon];
fRange := fRange - [rsAtClosingBracket];
end end
else else
fRange := fRange - [rsAtClosingBracket]; fRange := fRange - [rsAtClosingBracket];