mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 20:19:29 +02:00
FpDebug: PascalParser, fix error checking for sub-expressions in brackets
This commit is contained in:
parent
8bb9d6eece
commit
9a1ba57dc4
@ -346,6 +346,7 @@ type
|
|||||||
private
|
private
|
||||||
FIsClosed: boolean;
|
FIsClosed: boolean;
|
||||||
FIsClosing: boolean;
|
FIsClosing: boolean;
|
||||||
|
FIsSeparatorChecking: boolean;
|
||||||
FAfterComma: Integer;
|
FAfterComma: Integer;
|
||||||
FFullEndChar: PChar;
|
FFullEndChar: PChar;
|
||||||
function GetAfterComma: Boolean;
|
function GetAfterComma: Boolean;
|
||||||
@ -358,8 +359,9 @@ type
|
|||||||
procedure SetAfterCommaFlag;
|
procedure SetAfterCommaFlag;
|
||||||
property AfterComma: Boolean read GetAfterComma;
|
property AfterComma: Boolean read GetAfterComma;
|
||||||
procedure GetFirstLastChar(out AFirst, ALast: PChar); override;
|
procedure GetFirstLastChar(out AFirst, ALast: PChar); override;
|
||||||
|
procedure CheckBeforeSeparator(APart: TFpPascalExpressionPart);
|
||||||
public
|
public
|
||||||
procedure CloseBracket(AStartChar: PChar; AnEndChar: PChar = nil);
|
procedure CloseBracket(ALastAddedPart: TFpPascalExpressionPart; AStartChar: PChar; AnEndChar: PChar = nil);
|
||||||
function HandleNextPart(APart: TFpPascalExpressionPart): TFpPascalExpressionPart; override;
|
function HandleNextPart(APart: TFpPascalExpressionPart): TFpPascalExpressionPart; override;
|
||||||
procedure HandleEndOfExpression; override;
|
procedure HandleEndOfExpression; override;
|
||||||
property IsClosed: boolean read FIsClosed;
|
property IsClosed: boolean read FIsClosed;
|
||||||
@ -1836,6 +1838,7 @@ begin
|
|||||||
|
|
||||||
Result := (Count > FAfterComma) and (Count > 1); // First element is name of array (in front of "[")
|
Result := (Count > FAfterComma) and (Count > 1); // First element is name of array (in front of "[")
|
||||||
if Result then begin
|
if Result then begin
|
||||||
|
CheckBeforeSeparator(APart);
|
||||||
SetAfterCommaFlag;
|
SetAfterCommaFlag;
|
||||||
APart := Self;
|
APart := Self;
|
||||||
end;
|
end;
|
||||||
@ -1871,6 +1874,7 @@ begin
|
|||||||
|
|
||||||
Result := (Count > FAfterComma) and (Count > 0);
|
Result := (Count > FAfterComma) and (Count > 0);
|
||||||
if Result then begin
|
if Result then begin
|
||||||
|
CheckBeforeSeparator(APart);
|
||||||
SetAfterCommaFlag;
|
SetAfterCommaFlag;
|
||||||
APart := Self;
|
APart := Self;
|
||||||
end;
|
end;
|
||||||
@ -2054,6 +2058,7 @@ begin
|
|||||||
|
|
||||||
Result := (Count > FAfterComma) and (Count > 1); // First element is name of function (in front of "(")
|
Result := (Count > FAfterComma) and (Count > 1); // First element is name of function (in front of "(")
|
||||||
if Result then begin
|
if Result then begin
|
||||||
|
CheckBeforeSeparator(APart);
|
||||||
SetAfterCommaFlag;
|
SetAfterCommaFlag;
|
||||||
APart := Self;
|
APart := Self;
|
||||||
end;
|
end;
|
||||||
@ -3673,7 +3678,7 @@ var
|
|||||||
SetParserError(fpErrPasParserWrongOpenBracket_p, [GetFirstToken(CurPtr), PosFromPChar(BracketPart.StartChar), BracketPart.GetText(MAX_ERR_EXPR_QUOTE_LEN)]);
|
SetParserError(fpErrPasParserWrongOpenBracket_p, [GetFirstToken(CurPtr), PosFromPChar(BracketPart.StartChar), BracketPart.GetText(MAX_ERR_EXPR_QUOTE_LEN)]);
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
TFpPascalExpressionPartBracket(BracketPart).CloseBracket(CurPtr, TokenEndPtr-1);
|
TFpPascalExpressionPartBracket(BracketPart).CloseBracket(CurPart, CurPtr, TokenEndPtr-1);
|
||||||
CurPart := BracketPart;
|
CurPart := BracketPart;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -4587,7 +4592,17 @@ begin
|
|||||||
inherited GetFirstLastChar(AFirst, ALast);
|
inherited GetFirstLastChar(AFirst, ALast);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFpPascalExpressionPartBracket.CloseBracket(AStartChar: PChar; AnEndChar: PChar);
|
procedure TFpPascalExpressionPartBracket.CheckBeforeSeparator(APart: TFpPascalExpressionPart);
|
||||||
|
begin
|
||||||
|
if APart = nil then
|
||||||
|
exit;
|
||||||
|
FIsSeparatorChecking := True;
|
||||||
|
APart.HandleEndOfExpression;
|
||||||
|
FIsSeparatorChecking := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFpPascalExpressionPartBracket.CloseBracket(ALastAddedPart: TFpPascalExpressionPart;
|
||||||
|
AStartChar: PChar; AnEndChar: PChar);
|
||||||
begin
|
begin
|
||||||
FFullEndChar := AnEndChar;
|
FFullEndChar := AnEndChar;
|
||||||
if AfterComma then begin
|
if AfterComma then begin
|
||||||
@ -4595,8 +4610,8 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
FIsClosing := True;
|
FIsClosing := True;
|
||||||
if LastItem <> nil then
|
if ALastAddedPart <> nil then
|
||||||
LastItem.HandleEndOfExpression;
|
ALastAddedPart.HandleEndOfExpression;
|
||||||
FIsClosing := False;
|
FIsClosing := False;
|
||||||
FIsClosed := True;
|
FIsClosed := True;
|
||||||
end;
|
end;
|
||||||
@ -4620,7 +4635,7 @@ end;
|
|||||||
|
|
||||||
procedure TFpPascalExpressionPartBracket.HandleEndOfExpression;
|
procedure TFpPascalExpressionPartBracket.HandleEndOfExpression;
|
||||||
begin
|
begin
|
||||||
if not FIsClosing then
|
if not (FIsClosing or FIsSeparatorChecking) then
|
||||||
inherited HandleEndOfExpression;
|
inherited HandleEndOfExpression;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -615,6 +615,21 @@ begin
|
|||||||
AssertFalse('self test format error msg', pos('Internal Error:', s) < 1);
|
AssertFalse('self test format error msg', pos('Internal Error:', s) < 1);
|
||||||
|
|
||||||
|
|
||||||
|
//TestExpr('(a+2*)', fpErrPasParser);
|
||||||
|
CreateExpr('a+', False);
|
||||||
|
CreateExpr('a*', False);
|
||||||
|
CreateExpr('*a', False);
|
||||||
|
CreateExpr('a+2*', False);
|
||||||
|
CreateExpr('a*2+', False);
|
||||||
|
CreateExpr('(a+2*)', False);
|
||||||
|
CreateExpr('(a+2*)', False);
|
||||||
|
CreateExpr('f(a+2*)', False);
|
||||||
|
CreateExpr('f(1,a+2*)', False);
|
||||||
|
CreateExpr('f(1,a+2*)', False);
|
||||||
|
CreateExpr('f(a+2*)', False);
|
||||||
|
CreateExpr('f(a+2*,1)', False);
|
||||||
|
CreateExpr('f(a+2*,1)', False);
|
||||||
|
|
||||||
TestExpr('£', fpErrPasParserUnexpectedToken_p);
|
TestExpr('£', fpErrPasParserUnexpectedToken_p);
|
||||||
TestExpr(':foobar', fpErrPasParserUnknownIntrinsic_p);
|
TestExpr(':foobar', fpErrPasParserUnknownIntrinsic_p);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user