Browse Source

* TPasParser.ParseAdhocExpression implemented + test

git-svn-id: trunk@46933 -
joost 4 years ago
parent
commit
69b1d61a76

+ 6 - 0
packages/fcl-passrc/src/pparser.pp

@@ -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;

+ 18 - 0
packages/fcl-passrc/tests/tcexprparser.pas

@@ -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);

+ 4 - 4
packages/fcl-passrc/tests/testpassrc.lpr

@@ -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