codetools: fixed anonymous expr as arg and dot operator

git-svn-id: trunk@59845 -
This commit is contained in:
mattias 2018-12-18 12:41:17 +00:00
parent fc5c60b0fd
commit 7feb086d64
2 changed files with 43 additions and 24 deletions

View File

@ -1913,6 +1913,7 @@ function TCustomCodeTool.ReadTilBracketClose(
// after call cursor is on the closing bracket
var CloseBracket, AntiCloseBracket: TCommonAtomFlag;
Start: TAtomPosition;
Node: TCodeTreeNode;
procedure RaiseBracketNotFound;
begin
@ -1921,6 +1922,13 @@ var CloseBracket, AntiCloseBracket: TCommonAtomFlag;
else
SaveRaiseExceptionFmt(20170421194740,ctsBracketNotFound,[']'],false);
end;
procedure RaiseAtNicePos;
begin
SetNiceErrorPos(Start.StartPos);
if ExceptionOnNotFound then
RaiseBracketNotFound;
end;
begin
Result:=false;
@ -1942,12 +1950,21 @@ begin
if (CurPos.StartPos>SrcLen)
or (CurPos.Flag in [cafEnd,AntiCloseBracket])
then begin
SetNiceErrorPos(Start.StartPos);
if ExceptionOnNotFound then begin
RaiseBracketNotFound;
end;
RaiseAtNicePos;
exit;
end;
if (CurPos.Flag=cafWord) and (UpAtomIs('PROCEDURE') or UpAtomIs('FUNCTION'))
then begin
// check for anonymous function
Node:=FindDeepestNodeAtPos(CurPos.StartPos+1,false);
if (Node<>nil) and (Node.Desc=ctnProcedure) then
begin
MoveCursorToCleanPos(Node.EndPos);
end else begin
RaiseAtNicePos;
exit;
end;
end;
if (CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen]) then begin
if not ReadTilBracketClose(ExceptionOnNotFound) then exit;
end;
@ -1958,9 +1975,8 @@ end;
function TCustomCodeTool.ReadBackTilBracketOpen(
ExceptionOnNotFound: boolean): boolean;
// reads code brackets (not comment brackets)
var OpenBracket, AntiOpenBracket: TCommonAtomFlag;
Start: TAtomPosition;
var OpenBracket: TCommonAtomFlag;
procedure RaiseBracketNotFound;
begin
if OpenBracket=cafRoundBracketOpen then
@ -1969,6 +1985,10 @@ var OpenBracket, AntiOpenBracket: TCommonAtomFlag;
SaveRaiseExceptionFmt(20170421194749,ctsBracketNotFound,['[']);
end;
var
AntiOpenBracket: TCommonAtomFlag;
Start: TAtomPosition;
Node: TCodeTreeNode;
begin
Result:=false;
if (CurPos.Flag=cafRoundBracketClose) then begin
@ -1987,12 +2007,18 @@ begin
ReadPriorAtom;
if (CurPos.Flag=OpenBracket) then exit(true);
if (CurPos.StartPos<1)
or (CurPos.Flag in [AntiOpenBracket,cafEND])
or ((CurPos.Flag=cafWord)
and UnexpectedKeyWordInBrackets.DoItCaseInsensitive(Src,
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos))
then begin
or (CurPos.Flag=AntiOpenBracket) then
break;
if (CurPos.Flag=cafEnd) then begin
// check if anonymous function
Node:=FindDeepestNodeAtPos(CurPos.StartPos,true);
if (Node<>nil) and (Node.EndPos=CurPos.EndPos)
and (Node.Desc in [ctnBeginBlock,ctnAsmBlock])
and (Node.Parent.Desc=ctnProcedure) then
// ToDo: check if Node is anonymous procedure
MoveCursorToCleanPos(Node.Parent.StartPos)
else
break;
end;
if CurPos.Flag in [cafRoundBracketClose,cafEdgedBracketClose] then begin
if not ReadBackTilBracketOpen(ExceptionOnNotFound) then exit;

View File

@ -6044,7 +6044,7 @@ function TPascalParserTool.ReadClosure(ExceptionOnError, CreateNodes: boolean
}
var
Attr: TProcHeadAttributes;
IsFunction, IsBegin: boolean;
IsFunction: boolean;
Last: TAtomPosition;
begin
Result:=false;
@ -6107,7 +6107,6 @@ begin
CurNode.EndPos:=CurPos.StartPos;
EndChildNode;
end;
IsBegin:=false;
repeat
{$IFDEF VerboseReadClosure}
writeln('TPascalParserTool.ReadClosure body ',GetAtom,' CurNode=',NodeDescToStr(CurNode.Desc));
@ -6115,7 +6114,6 @@ begin
if CurPos.Flag=cafSemicolon then begin
ReadNextAtom;
end else if UpAtomIs('BEGIN') then begin
IsBegin:=true;
break;
end else if UpAtomIs('ASM') then begin
break;
@ -6140,20 +6138,15 @@ begin
{$IFDEF VerboseReadClosure}
writeln('TPascalParserTool.ReadClosure begin/asm ',GetAtom,' CurNode=',NodeDescToStr(CurNode.Desc));
{$ENDIF}
if CreateNodes then begin
CreateChildNode;
if IsBegin then
CurNode.Desc:=ctnBeginBlock
else
CurNode.Desc:=ctnAsmBlock;
end;
// search "end"
ReadTilBlockEnd(false,CreateNodes);
{$IFDEF VerboseReadClosure}
writeln('TPascalParserTool.ReadClosure END ',GetAtom,' CurNode=',NodeDescToStr(CurNode.Desc));
writeln('TPascalParserTool.ReadClosure END ',GetAtom,' CurNode=',NodeDescToStr(CurNode.Desc),' ',CurPos.EndPos);
{$ENDIF}
// close procedure node
if CreateNodes then begin
// close procedure node
if CurNode.Desc<>ctnProcedure then
RaiseUnexpectedKeyWord(20181218125659);
CurNode.EndPos:=CurPos.EndPos;
EndChildNode;
end;