Jedi Code Format: Deal with "Enumerator" when used as an identifier. Issue #38932, patch by Domingo Galmés.

git-svn-id: trunk@65219 -
This commit is contained in:
juha 2021-06-11 07:37:24 +00:00
parent a04f03d6df
commit 703f57c9f2
2 changed files with 31 additions and 10 deletions

View File

@ -272,7 +272,7 @@ type
procedure RecogniseAnonymousMethod; procedure RecogniseAnonymousMethod;
function AnonymousMethodNext: boolean; function AnonymousMethodNext: boolean;
procedure CheckEnumeratorToken;
Protected Protected
Public Public
@ -2526,6 +2526,7 @@ begin
PushNode(nFunctionHeading); PushNode(nFunctionHeading);
Recognise(ttOperator); Recognise(ttOperator);
CheckEnumeratorToken();
RecogniseOperatorSymbol(); RecogniseOperatorSymbol();
if fcTokenList.FirstSolidTokenType = ttOpenBracket then if fcTokenList.FirstSolidTokenType = ttOpenBracket then
@ -3962,6 +3963,7 @@ begin
Recognise(ttSemicolon); Recognise(ttSemicolon);
//opt //opt
CheckEnumeratorToken();
if fcTokenList.FirstSolidTokenType in ProcedureDirectives then if fcTokenList.FirstSolidTokenType in ProcedureDirectives then
RecogniseProcedureDirectives; RecogniseProcedureDirectives;
@ -3989,7 +3991,7 @@ begin
RecogniseConstructorHeading(False); RecogniseConstructorHeading(False);
Recognise(ttSemicolon); Recognise(ttSemicolon);
CheckEnumeratorToken();
if fcTokenList.FirstSolidTokenType in ProcedureDirectives then if fcTokenList.FirstSolidTokenType in ProcedureDirectives then
RecogniseProcedureDirectives; RecogniseProcedureDirectives;
RecogniseBlock; RecogniseBlock;
@ -4006,7 +4008,7 @@ begin
RecogniseDestructorHeading(False); RecogniseDestructorHeading(False);
Recognise(ttSemicolon); Recognise(ttSemicolon);
CheckEnumeratorToken();
if fcTokenList.FirstSolidTokenType in ProcedureDirectives then if fcTokenList.FirstSolidTokenType in ProcedureDirectives then
RecogniseProcedureDirectives; RecogniseProcedureDirectives;
RecogniseBlock; RecogniseBlock;
@ -4215,7 +4217,7 @@ begin
external is more complex external is more complex
} }
CheckEnumeratorToken();
if (fcTokenList.FirstSolidTokenType in ProcedureDirectives) or if (fcTokenList.FirstSolidTokenType in ProcedureDirectives) or
((fcTokenList.FirstSolidTokenType = ttSemicolon) and ((fcTokenList.FirstSolidTokenType = ttSemicolon) and
(fcTokenList.SolidTokenType(2) in ProcedureDirectives)) then (fcTokenList.SolidTokenType(2) in ProcedureDirectives)) then
@ -4226,6 +4228,7 @@ begin
Recognise(ttSemiColon); Recognise(ttSemiColon);
lbFirstPass := True; lbFirstPass := True;
CheckEnumeratorToken();
while (fcTokenList.FirstSolidTokenType in ProcedureDirectives) or while (fcTokenList.FirstSolidTokenType in ProcedureDirectives) or
((fcTokenList.FirstSolidTokenType = ttSemicolon) and ((fcTokenList.FirstSolidTokenType = ttSemicolon) and
(fcTokenList.SolidTokenType(2) in ProcedureDirectives)) do (fcTokenList.SolidTokenType(2) in ProcedureDirectives)) do
@ -4270,6 +4273,7 @@ begin
end; end;
lbFirstPass := False; lbFirstPass := False;
CheckEnumeratorToken();
end; end;
PopNode; PopNode;
@ -5688,13 +5692,14 @@ const
} }
PropertyDirectives = [ttDefault, ttNoDefault, ttStored, ttEnumerator]; PropertyDirectives = [ttDefault, ttNoDefault, ttStored, ttEnumerator];
begin begin
CheckEnumeratorToken();
if ((fcTokenList.FirstSolidTokenType = ttSemicolon) and if ((fcTokenList.FirstSolidTokenType = ttSemicolon) and
(fcTokenList.SolidTokenType(2) in PropertyDirectives)) or (fcTokenList.SolidTokenType(2) in PropertyDirectives)) or
(fcTokenList.FirstSolidTokenType in PropertyDirectives) then (fcTokenList.FirstSolidTokenType in PropertyDirectives) then
begin begin
if fcTokenList.FirstSolidTokenType = ttSemicolon then if fcTokenList.FirstSolidTokenType = ttSemicolon then
Recognise(ttSemicolon); Recognise(ttSemicolon);
CheckEnumeratorToken();
while fcTokenList.FirstSolidTokenType in PropertyDirectives do while fcTokenList.FirstSolidTokenType in PropertyDirectives do
begin begin
PushNode(nPropertyDirective); PushNode(nPropertyDirective);
@ -5720,14 +5725,12 @@ begin
begin begin
Recognise(ttEnumerator); Recognise(ttEnumerator);
RecogniseIdentifier(False, idStrict); RecogniseIdentifier(False, idStrict);
end;
end; end;
end;
PopNode; PopNode;
CheckEnumeratorToken();
end; end;
end; end;
end; end;
procedure TBuildParseTree.RecogniseExportsSection; procedure TBuildParseTree.RecogniseExportsSection;
@ -5924,6 +5927,23 @@ begin
end; end;
end; end;
procedure TBuildParseTree.CheckEnumeratorToken;
var
lc: TSourceToken;
begin
lc := fcTokenList.FirstSolidToken;
if (lc.TokenType=ttIdentifier) and (length(lc.SourceCode)=10) and (lowercase(lc.SourceCode)='enumerator') then
begin
lc.TokenType:=ttEnumerator;
lc.WordType:=wtReservedWord;
end;
lc := fcTokenList.SolidToken(2);
if (lc.TokenType=ttIdentifier) and (length(lc.SourceCode)=10) and (lowercase(lc.SourceCode)='enumerator') then
begin
lc.TokenType:=ttEnumerator;
lc.WordType:=wtReservedWord;
end;
end;
procedure TBuildParseTree.RecogniseLiteralString; procedure TBuildParseTree.RecogniseLiteralString;
begin begin

View File

@ -624,7 +624,8 @@ begin
AddKeyword('downto', wtReservedWord, ttDownTo); AddKeyword('downto', wtReservedWord, ttDownTo);
AddKeyword('else', wtReservedWord, ttElse); AddKeyword('else', wtReservedWord, ttElse);
AddKeyword('end', wtReservedWord, ttEnd); AddKeyword('end', wtReservedWord, ttEnd);
AddKeyword('enumerator', wtReservedWord, ttEnumerator); // 'enumerator' can be a valid identifier.
//AddKeyword('enumerator', wtReservedWord, ttEnumerator);
AddKeyword('except', wtReservedWord, ttExcept); AddKeyword('except', wtReservedWord, ttExcept);
AddKeyword('exports', wtReservedWord, ttExports); AddKeyword('exports', wtReservedWord, ttExports);
AddKeyword('file', wtReservedWord, ttFile); AddKeyword('file', wtReservedWord, ttFile);