SynEdit: Pas-HL: fix detection of case...else versus if...then...else

git-svn-id: trunk@37518 -
This commit is contained in:
martin 2012-06-04 17:26:35 +00:00
parent af1af6709d
commit 634c42c057

View File

@ -124,6 +124,8 @@ type
// Internal type / not configurable
cfbtCaseElse, // "else" in case can have multiply statements
cfbtPackage,
cfbtIfThen,
//cfbtIfElse,
cfbtNone
);
TPascalCodeFoldBlockTypes = set of TPascalCodeFoldBlockType;
@ -148,7 +150,7 @@ const
PascalStatementBlocks: TPascalCodeFoldBlockTypes =
[cfbtBeginEnd, cfbtTopBeginEnd, cfbtCase, cfbtTry, cfbtExcept, cfbtRepeat,
cfbtCaseElse];
cfbtCaseElse, cfbtIfThen];
PascalFoldTypeCompatibility: Array [TPascalCodeFoldBlockType] of TPascalCodeFoldBlockType =
( cfbtBeginEnd, // Nested
@ -177,6 +179,7 @@ const
// Internal type / not configurable
cfbtCaseElse,
cfbtPackage,
cfbtIfThen,
cfbtNone
);
@ -918,6 +921,10 @@ begin
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
// there may be more than on block ending here
tfb := TopPascalCodeFoldBlockType;
while (tfb = cfbtIfThen) do begin // no semicolon before end
EndPascalCodeFoldBlock;
tfb := TopPascalCodeFoldBlockType;
end;
if tfb = cfbtRecord then begin
EndPascalCodeFoldBlock;
end else if tfb = cfbtUnit then begin
@ -1080,8 +1087,11 @@ function TSynPasSyn.Func41: TtkTokenKind;
begin
if KeyComp('Else') then begin
Result := tkKey;
if TopPascalCodeFoldBlockType = cfbtCase
then StartPascalCodeFoldBlock(cfbtCaseElse)
if (TopPascalCodeFoldBlockType = cfbtIfThen) then
EndPascalCodeFoldBlock
else
if TopPascalCodeFoldBlockType = cfbtCase then
StartPascalCodeFoldBlock(cfbtCaseElse)
end
else if KeyComp('Var') then begin
if (PasCodeFoldRange.BracketNestLevel = 0) and
@ -1147,8 +1157,12 @@ end;
function TSynPasSyn.Func47: TtkTokenKind;
begin
if KeyComp('Then') then
Result := tkKey
if KeyComp('Then') then begin
Result := tkKey;
// in a "case", we need to distinguish a possible follwing "else"
if TopPascalCodeFoldBlockType in [cfbtCase, cfbtIfThen] then
StartPascalCodeFoldBlock(cfbtIfThen);
end
else
Result := tkIdentifier;
end;
@ -1384,6 +1398,8 @@ function TSynPasSyn.Func73: TtkTokenKind;
begin
if KeyComp('Except') then begin
Result := tkKey;
while (TopPascalCodeFoldBlockType = cfbtIfThen) do // no semicolon before except
EndPascalCodeFoldBlock;
SmartCloseBeginEndBlocks(cfbtTry);
if TopPascalCodeFoldBlockType = cfbtTry then
StartPascalCodeFoldBlock(cfbtExcept);
@ -1408,6 +1424,8 @@ function TSynPasSyn.Func76: TtkTokenKind;
begin
if KeyComp('Until') then begin
Result := tkKey;
while (TopPascalCodeFoldBlockType = cfbtIfThen) do // no semicolon before until
EndPascalCodeFoldBlock;
SmartCloseBeginEndBlocks(cfbtRepeat);
if TopPascalCodeFoldBlockType = cfbtRepeat then EndPascalCodeFoldBlock;
end
@ -1418,6 +1436,8 @@ function TSynPasSyn.Func79: TtkTokenKind;
begin
if KeyComp('Finally') then begin
Result := tkKey;
while (TopPascalCodeFoldBlockType = cfbtIfThen) do // no semicolon before finally
EndPascalCodeFoldBlock;
SmartCloseBeginEndBlocks(cfbtTry);
if TopPascalCodeFoldBlockType = cfbtTry then
StartPascalCodeFoldBlock(cfbtExcept);
@ -2751,6 +2771,11 @@ begin
if (tfb = cfbtClass) and (rsAfterClass in fRange) then
EndPascalCodeFoldBlock(True);
while (tfb = cfbtIfThen) do begin
EndPascalCodeFoldBlock;
tfb := TopPascalCodeFoldBlockType;
end;
if (tfb = cfbtCase) then
fRange := fRange + [rsAtCaseLabel];