mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-07 18:55:56 +02:00
codetools: indentation parser: case
git-svn-id: trunk@20206 -
This commit is contained in:
parent
bea4284a74
commit
103696b790
@ -83,13 +83,20 @@ type
|
|||||||
bbtVarSection,
|
bbtVarSection,
|
||||||
bbtResourceStringSection,
|
bbtResourceStringSection,
|
||||||
bbtLabelSection,
|
bbtLabelSection,
|
||||||
|
// type blocks
|
||||||
|
bbtRecord,
|
||||||
// statement blocks
|
// statement blocks
|
||||||
bbtProcedure, // procedure, constructor, destructor
|
bbtProcedure, // procedure, constructor, destructor
|
||||||
bbtFunction,
|
bbtFunction,
|
||||||
bbtMainBegin,
|
bbtMainBegin,
|
||||||
bbtCommentaryBegin, // begin without any need
|
bbtCommentaryBegin, // begin without any need
|
||||||
bbtRepeat,
|
bbtRepeat,
|
||||||
bbtProcedureBegin
|
bbtProcedureBegin,
|
||||||
|
bbtCase,
|
||||||
|
bbtCaseOf, // child of bbtCase
|
||||||
|
bbtCaseColon, // child of bbtCase
|
||||||
|
bbtCaseBegin, // child of bbtCaseColon
|
||||||
|
bbtCaseElse // child of bbtCase
|
||||||
);
|
);
|
||||||
TFABBlockTypes = set of TFABBlockType;
|
TFABBlockTypes = set of TFABBlockType;
|
||||||
|
|
||||||
@ -98,7 +105,8 @@ const
|
|||||||
bbtResourceStringSection,bbtLabelSection];
|
bbtResourceStringSection,bbtLabelSection];
|
||||||
bbtAllCodeSections = [bbtInterface,bbtImplementation,bbtInitialization,
|
bbtAllCodeSections = [bbtInterface,bbtImplementation,bbtInitialization,
|
||||||
bbtFinalization];
|
bbtFinalization];
|
||||||
bbtAllStatements = [bbtMainBegin,bbtCommentaryBegin,bbtRepeat];
|
bbtAllStatements = [bbtMainBegin,bbtCommentaryBegin,bbtRepeat,
|
||||||
|
bbtCaseColon,bbtCaseBegin,bbtCaseElse];
|
||||||
type
|
type
|
||||||
TOnGetFABExamples = procedure(Sender: TObject; Code: TCodeBuffer;
|
TOnGetFABExamples = procedure(Sender: TObject; Code: TCodeBuffer;
|
||||||
out CodeBuffers: TFPList) of object;
|
out CodeBuffers: TFPList) of object;
|
||||||
@ -167,13 +175,20 @@ const
|
|||||||
'bbtVarSection',
|
'bbtVarSection',
|
||||||
'bbtResourceStringSection',
|
'bbtResourceStringSection',
|
||||||
'bbtLabelSection',
|
'bbtLabelSection',
|
||||||
|
// type blocks
|
||||||
|
'bbtRecord',
|
||||||
// statement blocks
|
// statement blocks
|
||||||
'bbtProcedure',
|
'bbtProcedure',
|
||||||
'bbtFunction',
|
'bbtFunction',
|
||||||
'bbtMainBegin',
|
'bbtMainBegin',
|
||||||
'bbtCommentaryBegin',
|
'bbtCommentaryBegin',
|
||||||
'bbtRepeat',
|
'bbtRepeat',
|
||||||
'bbtProcedureBegin'
|
'bbtProcedureBegin',
|
||||||
|
'bbtCase',
|
||||||
|
'bbtCaseOf',
|
||||||
|
'bbtCaseColon',
|
||||||
|
'bbtCaseBegin',
|
||||||
|
'bbtCaseElse'
|
||||||
);
|
);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -341,7 +356,7 @@ var
|
|||||||
end;
|
end;
|
||||||
if Stack.TopType in bbtAllIdentifierSections then
|
if Stack.TopType in bbtAllIdentifierSections then
|
||||||
EndBlock;
|
EndBlock;
|
||||||
if Stack.TopType in (bbtAllCodeSections+[bbtProcedure,bbtFunction]) then
|
if Stack.TopType in (bbtAllCodeSections+[bbtNone,bbtProcedure,bbtFunction]) then
|
||||||
BeginBlock(Section);
|
BeginBlock(Section);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -358,7 +373,7 @@ var
|
|||||||
end;
|
end;
|
||||||
if Stack.TopType in bbtAllIdentifierSections then
|
if Stack.TopType in bbtAllIdentifierSections then
|
||||||
EndBlock;
|
EndBlock;
|
||||||
if Stack.TopType in (bbtAllCodeSections+[bbtProcedure,bbtFunction]) then
|
if Stack.TopType in (bbtAllCodeSections+[bbtNone,bbtProcedure,bbtFunction]) then
|
||||||
BeginBlock(Typ);
|
BeginBlock(Typ);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -403,29 +418,58 @@ begin
|
|||||||
BeginBlock(bbtProcedureBegin);
|
BeginBlock(bbtProcedureBegin);
|
||||||
bbtMainBegin:
|
bbtMainBegin:
|
||||||
BeginBlock(bbtCommentaryBegin);
|
BeginBlock(bbtCommentaryBegin);
|
||||||
|
bbtCaseElse,bbtCaseColon:
|
||||||
|
BeginBlock(bbtCaseBegin);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
'C':
|
'C':
|
||||||
if CompareIdentifiers('CONST',r)=0 then begin
|
case UpChars[r[1]] of
|
||||||
StartIdentifierSection(bbtConstSection);
|
'A': // CA
|
||||||
|
if CompareIdentifiers('CASE',r)=0 then begin
|
||||||
|
if Stack.TopType in bbtAllStatements then
|
||||||
|
BeginBlock(bbtCase);
|
||||||
|
end;
|
||||||
|
'O': // CO
|
||||||
|
if CompareIdentifiers('CONST',r)=0 then
|
||||||
|
StartIdentifierSection(bbtConstSection);
|
||||||
end;
|
end;
|
||||||
'E':
|
'E':
|
||||||
if CompareIdentifiers('END',r)=0 then begin
|
case UpChars[r[1]] of
|
||||||
case Stack.TopType of
|
'L': // EL
|
||||||
bbtMainBegin,bbtCommentaryBegin:
|
if CompareIdentifiers('ELSE',r)=0 then begin
|
||||||
EndBlock;
|
case Stack.TopType of
|
||||||
bbtProcedureBegin:
|
bbtCaseOf,bbtCaseColon:
|
||||||
begin
|
begin
|
||||||
EndBlock;
|
|
||||||
if Stack.TopType in [bbtProcedure,bbtFunction] then
|
|
||||||
EndBlock;
|
EndBlock;
|
||||||
|
BeginBlock(bbtCaseElse);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
'N': // EN
|
||||||
|
if CompareIdentifiers('END',r)=0 then begin
|
||||||
|
case Stack.TopType of
|
||||||
|
bbtMainBegin,bbtCommentaryBegin,
|
||||||
|
bbtRecord,
|
||||||
|
bbtCase,bbtCaseBegin:
|
||||||
|
EndBlock;
|
||||||
|
bbtCaseOf,bbtCaseElse,bbtCaseColon:
|
||||||
|
begin
|
||||||
|
EndBlock;
|
||||||
|
if Stack.TopType=bbtCase then
|
||||||
|
EndBlock;
|
||||||
|
end;
|
||||||
|
bbtProcedureBegin:
|
||||||
|
begin
|
||||||
|
EndBlock;
|
||||||
|
if Stack.TopType in [bbtProcedure,bbtFunction] then
|
||||||
|
EndBlock;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
StartIdentifierSection(bbtConstSection);
|
|
||||||
end;
|
end;
|
||||||
'F':
|
'F':
|
||||||
case UpChars[r[1]] of
|
case UpChars[r[1]] of
|
||||||
'I':
|
'I': // FI
|
||||||
if CompareIdentifiers('FINALIZATION',r)=0 then begin
|
if CompareIdentifiers('FINALIZATION',r)=0 then begin
|
||||||
while Stack.TopType in (bbtAllCodeSections+bbtAllIdentifierSections)
|
while Stack.TopType in (bbtAllCodeSections+bbtAllIdentifierSections)
|
||||||
do
|
do
|
||||||
@ -433,21 +477,21 @@ begin
|
|||||||
if Stack.TopType=bbtNone then
|
if Stack.TopType=bbtNone then
|
||||||
BeginBlock(bbtInitialization);
|
BeginBlock(bbtInitialization);
|
||||||
end;
|
end;
|
||||||
'O':
|
'O': // FO
|
||||||
if CompareIdentifiers('FORWARD',r)=0 then begin
|
if CompareIdentifiers('FORWARD',r)=0 then begin
|
||||||
if Stack.TopType in [bbtProcedure,bbtFunction] then begin
|
if Stack.TopType in [bbtProcedure,bbtFunction] then begin
|
||||||
EndBlock;
|
EndBlock;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
'U':
|
'U': // FU
|
||||||
if CompareIdentifiers('FUNCTION',r)=0 then
|
if CompareIdentifiers('FUNCTION',r)=0 then
|
||||||
StartProcedure(bbtFunction);
|
StartProcedure(bbtFunction);
|
||||||
end;
|
end;
|
||||||
'I':
|
'I':
|
||||||
case UpChars[Src[1]] of
|
case UpChars[Src[1]] of
|
||||||
'N':
|
'N': // IN
|
||||||
case UpChars[Src[2]] of
|
case UpChars[Src[2]] of
|
||||||
'I':
|
'I': // INI
|
||||||
if CompareIdentifiers('INITIALIZATION',r)=0 then begin
|
if CompareIdentifiers('INITIALIZATION',r)=0 then begin
|
||||||
while Stack.TopType in (bbtAllCodeSections+bbtAllIdentifierSections)
|
while Stack.TopType in (bbtAllCodeSections+bbtAllIdentifierSections)
|
||||||
do
|
do
|
||||||
@ -455,13 +499,13 @@ begin
|
|||||||
if Stack.TopType=bbtNone then
|
if Stack.TopType=bbtNone then
|
||||||
BeginBlock(bbtInitialization);
|
BeginBlock(bbtInitialization);
|
||||||
end;
|
end;
|
||||||
'T':
|
'T': // INT
|
||||||
if CompareIdentifiers('INTERFACE',r)=0 then begin
|
if CompareIdentifiers('INTERFACE',r)=0 then begin
|
||||||
if Stack.TopType=bbtNone then
|
if Stack.TopType=bbtNone then
|
||||||
BeginBlock(bbtInterface);
|
BeginBlock(bbtInterface);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
'M':
|
'M': // IM
|
||||||
if CompareIdentifiers('IMPLEMENTATION',r)=0 then begin
|
if CompareIdentifiers('IMPLEMENTATION',r)=0 then begin
|
||||||
while Stack.TopType in (bbtAllCodeSections+bbtAllIdentifierSections)
|
while Stack.TopType in (bbtAllCodeSections+bbtAllIdentifierSections)
|
||||||
do
|
do
|
||||||
@ -473,19 +517,26 @@ begin
|
|||||||
'L':
|
'L':
|
||||||
if CompareIdentifiers('LABEL',r)=0 then
|
if CompareIdentifiers('LABEL',r)=0 then
|
||||||
StartIdentifierSection(bbtLabelSection);
|
StartIdentifierSection(bbtLabelSection);
|
||||||
|
'O':
|
||||||
|
if CompareIdentifiers('OF',r)=0 then begin
|
||||||
|
if Stack.TopType=bbtCase then
|
||||||
|
BeginBlock(bbtCaseOf);
|
||||||
|
end;
|
||||||
'P':
|
'P':
|
||||||
if CompareIdentifiers('PROCEDURE',r)=0 then
|
if CompareIdentifiers('PROCEDURE',r)=0 then
|
||||||
StartProcedure(bbtProcedure);
|
StartProcedure(bbtProcedure);
|
||||||
'R':
|
'R':
|
||||||
case UpChars[r[1]] of
|
case UpChars[r[1]] of
|
||||||
'E':
|
'E': // RE
|
||||||
case UpChars[r[2]] of
|
case UpChars[r[2]] of
|
||||||
'P':
|
'C': // REC
|
||||||
if CompareIdentifiers('REPEAT',r)=0 then begin
|
if CompareIdentifiers('RECORD',r)=0 then
|
||||||
|
BeginBlock(bbtRecord);
|
||||||
|
'P': // REP
|
||||||
|
if CompareIdentifiers('REPEAT',r)=0 then
|
||||||
if Stack.TopType in bbtAllStatements then
|
if Stack.TopType in bbtAllStatements then
|
||||||
BeginBlock(bbtRepeat);
|
BeginBlock(bbtRepeat);
|
||||||
end;
|
'S': // RES
|
||||||
'S':
|
|
||||||
if CompareIdentifiers('RESOURCESTRING',r)=0 then
|
if CompareIdentifiers('RESOURCESTRING',r)=0 then
|
||||||
StartIdentifierSection(bbtResourceStringSection);
|
StartIdentifierSection(bbtResourceStringSection);
|
||||||
end;
|
end;
|
||||||
@ -496,12 +547,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
'U':
|
'U':
|
||||||
case UpChars[r[1]] of
|
case UpChars[r[1]] of
|
||||||
'S':
|
'S': // US
|
||||||
if CompareIdentifiers('USES',r)=0 then begin
|
if CompareIdentifiers('USES',r)=0 then begin
|
||||||
if Stack.TopType in [bbtNone,bbtInterface,bbtImplementation] then
|
if Stack.TopType in [bbtNone,bbtInterface,bbtImplementation] then
|
||||||
BeginBlock(bbtUsesSection);
|
BeginBlock(bbtUsesSection);
|
||||||
end;
|
end;
|
||||||
'N':
|
'N': // UN
|
||||||
if CompareIdentifiers('UNTIL',r)=0 then begin
|
if CompareIdentifiers('UNTIL',r)=0 then begin
|
||||||
EndTopMostBlock(bbtRepeat);
|
EndTopMostBlock(bbtRepeat);
|
||||||
end;
|
end;
|
||||||
@ -514,6 +565,22 @@ begin
|
|||||||
case Stack.TopType of
|
case Stack.TopType of
|
||||||
bbtUsesSection:
|
bbtUsesSection:
|
||||||
EndBlock;
|
EndBlock;
|
||||||
|
bbtCaseColon:
|
||||||
|
begin
|
||||||
|
EndBlock;
|
||||||
|
BeginBlock(bbtCaseOf);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
':':
|
||||||
|
if p-AtomStart=1 then begin
|
||||||
|
// colon
|
||||||
|
case Stack.TopType of
|
||||||
|
bbtCaseOf:
|
||||||
|
begin
|
||||||
|
EndBlock;
|
||||||
|
BeginBlock(bbtCaseColon);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
until false;
|
until false;
|
||||||
|
Loading…
Reference in New Issue
Block a user