From 68366d178c7b718731a8af52fdcdae804a74bc7f Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 4 Mar 2023 20:12:02 +0100 Subject: [PATCH] =?UTF-8?q?CodeTools:=20Fix=20parsing=20"with"=20statement?= =?UTF-8?q?,=20ended=20by=20outer=20block=20(repeat,=20try,=20if...)=20Iss?= =?UTF-8?q?ue=20#39684=20Patch=20by=20Domingo=20Galm=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/codetools/pascalparsertool.pas | 34 +++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index e26009ce2b..c24c0a640c 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -257,6 +257,7 @@ type function SkipTypeReference(ExceptionOnError: boolean): boolean; function SkipSpecializeParams(ExceptionOnError: boolean): boolean; function WordIsPropertyEnd: boolean; + function WordIsStatemendEnd: boolean; function AllowAttributes: boolean; inline; function AllowAnonymousFunctions: boolean; inline; public @@ -3249,6 +3250,26 @@ begin until false; end; +function TPascalParserTool.WordIsStatemendEnd: boolean; +var + p: PChar; +begin + p:=@Src[CurPos.StartPos]; + case UpChars[p^] of + 'E': + case UpChars[p[1]] of + 'L': if UpAtomIs('ELSE') then exit(true); + 'N': if UpAtomIs('END') then exit(true); + 'X': if UpAtomIs('EXCEPT') then exit(true); + end; + 'F': if UpAtomIs('FINALLY') then exit(true); + 'O': if UpAtomIs('OTHERWISE') then exit(true); + 'U': if UpAtomIs('UNTIL') then exit(true); + end; + Result:=false; +end; + + function TPascalParserTool.ReadTilStatementEnd(ExceptionOnError, CreateNodes: boolean): boolean; // after reading the current atom will be on the last atom of the statement @@ -3272,10 +3293,17 @@ begin exit; end; cafSemicolon: exit; - else - if CurPos.StartPos>SrcLen then exit; - ReadNextAtom; + cafWord: + begin + if WordIsStatemendEnd then + begin + UndoReadNextAtom; + exit; + end; + end; end; + if CurPos.StartPos>SrcLen then exit; + ReadNextAtom; end; end; end;