* TPasParser.ParseAdhocExpression implemented + test

git-svn-id: trunk@46933 -
This commit is contained in:
joost 2020-09-23 21:39:24 +00:00
parent dfc485c4f4
commit 69b1d61a76
3 changed files with 28 additions and 4 deletions

View File

@ -440,6 +440,7 @@ type
procedure ParseFinalization;
procedure ParseDeclarations(Declarations: TPasDeclarations);
procedure ParseStatement(Parent: TPasImplBlock; out NewImplElement: TPasImplElement);
procedure ParseAdhocExpression(out NewExprElement: TPasExpr);
procedure ParseLabels(AParent: TPasElement);
procedure ParseProcBeginBlock(Parent: TProcedureBody);
procedure ParseProcAsmBlock(Parent: TProcedureBody);
@ -7800,6 +7801,11 @@ begin
Result.Kind:=pekListOfExp;
end;
procedure TPasParser.ParseAdhocExpression(out NewExprElement: TPasExpr);
begin
NewExprElement := DoParseExpression(nil);
end;
initialization
{$IFDEF HASFS}
DefaultFileResolverClass:=TFileResolver;

View File

@ -150,6 +150,8 @@ type
Procedure TestExpCaret;
Procedure TestArrayAccess;
Procedure TestHelperOnLiteral;
procedure TestParseAdhocExpression;
end;
implementation
@ -1316,6 +1318,22 @@ begin
AssertExpression('right AS b',AsExpr.right,pekIdent,'b');
end;
procedure TTestExpressions.TestParseAdhocExpression;
var
ExprElement: TPasExpr;
BinaryExpression: TBinaryExpr;
begin
// Unlike the other tests, this is not about the parser, but about the
// ability to parse an expression on it's own. Without any further context.
Add('True=False');
StartParsing;
Parser.NextToken;
Parser.ParseAdhocExpression(ExprElement);
BinaryExpression := AssertExpression('Some expression, parsed separately',ExprElement,pekBinary,TBinaryExpr) as TBinaryExpr;
AssertExpression('Some expression, parsed separately, left part', BinaryExpression.left, pekBoolConst, TBoolConstExpr);
AssertExpression('Some expression, parsed separately, right part',BinaryExpression.right, pekBoolConst, TBoolConstExpr);
end;
initialization
RegisterTest(TTestExpressions);

View File

@ -4,10 +4,10 @@ program testpassrc;
uses
//MemCheck,
Classes, consoletestrunner, tcscanner, tctypeparser, tcstatements,
tcbaseparser, tcmoduleparser, tconstparser, tcvarparser, tcclasstype,
tcexprparser, tcprocfunc, tcpassrcutil, tcresolver, tcgenerics,
tcuseanalyzer, pasresolveeval, tcresolvegenerics;
Classes, consoletestrunner,{ tcscanner, tctypeparser, tcstatements,
tcbaseparser, tcmoduleparser, tconstparser, tcvarparser, tcclasstype,}
tcexprparser{, tcprocfunc, tcpassrcutil, tcresolver, tcgenerics,
tcuseanalyzer, pasresolveeval, tcresolvegenerics};
type