From 6cba62981b046b006079e57fa788f0d991b0de07 Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Wed, 2 Sep 2020 17:08:04 +0200 Subject: [PATCH] Allow if statements in py2yacs. --- src/py2yacs/Test/Py2yacsTest.cxx | 3 ++- src/py2yacs/Test/Py2yacsTest.hxx | 6 +++--- src/py2yacs/py2yacs.py | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/py2yacs/Test/Py2yacsTest.cxx b/src/py2yacs/Test/Py2yacsTest.cxx index 2f431a331..7f08682dc 100644 --- a/src/py2yacs/Test/Py2yacsTest.cxx +++ b/src/py2yacs/Test/Py2yacsTest.cxx @@ -220,6 +220,7 @@ void Py2yacsTest::unaccepted_statement() verifyWrongPycode(code_py, "f", "not accepted statement"); } +/* // This is now accepted void Py2yacsTest::unaccepted_statement2() { const char * code_py = "def f(a):\n" @@ -227,7 +228,7 @@ void Py2yacsTest::unaccepted_statement2() "if __name__ == '__main__':" " print('toto')\n"; verifyWrongPycode(code_py, "f", "not accepted statement"); -} +}*/ void Py2yacsTest::unaccepted_return() { diff --git a/src/py2yacs/Test/Py2yacsTest.hxx b/src/py2yacs/Test/Py2yacsTest.hxx index 82441b6d3..2285081dc 100644 --- a/src/py2yacs/Test/Py2yacsTest.hxx +++ b/src/py2yacs/Test/Py2yacsTest.hxx @@ -31,7 +31,7 @@ class Py2yacsTest: public CppUnit::TestFixture CPPUNIT_TEST(t5); CPPUNIT_TEST(no_multiple_returns); CPPUNIT_TEST(unaccepted_statement); - CPPUNIT_TEST(unaccepted_statement2); + //CPPUNIT_TEST(unaccepted_statement2); CPPUNIT_TEST(unaccepted_return); CPPUNIT_TEST(unaccepted_return2); CPPUNIT_TEST(syntaxError); @@ -52,7 +52,7 @@ class Py2yacsTest: public CppUnit::TestFixture void t5(); void no_multiple_returns(); void unaccepted_statement(); - void unaccepted_statement2(); + //void unaccepted_statement2(); void unaccepted_return(); void unaccepted_return2(); void syntaxError(); @@ -62,4 +62,4 @@ class Py2yacsTest: public CppUnit::TestFixture void globalVerification(); }; -#endif \ No newline at end of file +#endif diff --git a/src/py2yacs/py2yacs.py b/src/py2yacs/py2yacs.py index 3ee6251ae..ec4dae200 100644 --- a/src/py2yacs/py2yacs.py +++ b/src/py2yacs/py2yacs.py @@ -38,7 +38,7 @@ class FunctionProperties: class VisitAST(ast.NodeVisitor): def visit_Module(self, node): - accepted_tokens = ["Import", "ImportFrom", "FunctionDef", "ClassDef"] + accepted_tokens = ["Import", "ImportFrom", "FunctionDef", "ClassDef", "If"] self.global_errors=[] for e in node.body: type_name = type(e).__name__ @@ -158,10 +158,10 @@ def function_properties(python_path, fn_name): raise Exception("Function not found: {}".format(fn_name)) result = result[0] error_string = "" - #if len(errors) > 0: - #error_string += "Global errors in file {}\n".format(python_path) - #error_string += '\n'.join(errors) - #raise Exception(error_string) + if len(errors) > 0: + error_string += "Global errors in file {}\n".format(python_path) + error_string += '\n'.join(errors) + raise Exception(error_string) if len(result.errors) > 0: error_string += "Errors when parsing function {}\n".format(fn_name) error_string += '\n'.join(result.errors) -- 2.30.2