self.maxDiff = None
for source in TEST_SOURCES:
actual_ast = peg_parser.parse_string(source)
- expected_ast = ast.parse(source)
+ expected_ast = peg_parser.parse_string(source, oldparser=True)
self.assertEqual(
ast.dump(actual_ast, include_attributes=True),
ast.dump(expected_ast, include_attributes=True),
f"Actual error message does not match expexted for {source}"
)
- @support.skip_if_new_parser("This tests nothing for now, since compile uses pegen as well")
@unittest.expectedFailure
def test_correct_but_known_to_fail_ast_generation_on_source_files(self) -> None:
for source in GOOD_BUT_FAIL_SOURCES:
actual_ast = peg_parser.parse_string(source)
- expected_ast = ast.parse(source)
+ expected_ast = peg_parser.parse_string(source, oldparser=True)
self.assertEqual(
ast.dump(actual_ast, include_attributes=True),
ast.dump(expected_ast, include_attributes=True),
def test_correct_ast_generation_without_pos_info(self) -> None:
for source in GOOD_BUT_FAIL_SOURCES:
actual_ast = peg_parser.parse_string(source)
- expected_ast = ast.parse(source)
+ expected_ast = peg_parser.parse_string(source, oldparser=True)
self.assertEqual(
ast.dump(actual_ast),
ast.dump(expected_ast),
def test_correct_ast_generatrion_eval(self) -> None:
for source in EXPRESSIONS_TEST_SOURCES:
actual_ast = peg_parser.parse_string(source, mode='eval')
- expected_ast = ast.parse(source, mode='eval')
+ expected_ast = peg_parser.parse_string(source, mode='eval', oldparser=True)
self.assertEqual(
ast.dump(actual_ast, include_attributes=True),
ast.dump(expected_ast, include_attributes=True),
PyObject *
_Py_parse_string(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *keywords[] = {"string", "mode", NULL};
+ static char *keywords[] = {"string", "mode", "oldparser", NULL};
char *the_string;
char *mode_str = "exec";
+ int oldparser = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s", keywords, &the_string, &mode_str)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|sp", keywords,
+ &the_string, &mode_str, &oldparser)) {
return NULL;
}
PyCompilerFlags flags = _PyCompilerFlags_INIT;
flags.cf_flags = PyCF_IGNORE_COOKIE;
- mod_ty res = PyPegen_ASTFromString(the_string, mode, &flags, arena);
+ mod_ty res;
+ if (oldparser) {
+ res = PyParser_ASTFromString(the_string, "<string>", mode, &flags, arena);
+ }
+ else {
+ res = PyPegen_ASTFromString(the_string, mode, &flags, arena);
+ }
if (res == NULL) {
goto error;
}