diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2020-06-06 07:21:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 21:21:40 -0700 |
commit | ba6fd87e41dceb01dcdacc57c722aca12cde42a9 (patch) | |
tree | e6a79a37d80a59274b029050e24cf75893dd80cb /Modules/_peg_parser.c | |
parent | 2e6593db0086004a1ca7f7049218ff9573d473c2 (diff) | |
download | cpython-git-ba6fd87e41dceb01dcdacc57c722aca12cde42a9.tar.gz |
Refactor scripts in Tools/peg_generator/scripts (GH-20401)
Diffstat (limited to 'Modules/_peg_parser.c')
-rw-r--r-- | Modules/_peg_parser.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/_peg_parser.c b/Modules/_peg_parser.c index b66d5a83a8..ca2a3cf7b5 100644 --- a/Modules/_peg_parser.c +++ b/Modules/_peg_parser.c @@ -80,14 +80,15 @@ _Py_compile_string(PyObject *self, PyObject *args, PyObject *kwds) PyObject * _Py_parse_string(PyObject *self, PyObject *args, PyObject *kwds) { - static char *keywords[] = {"string", "filename", "mode", "oldparser", NULL}; + static char *keywords[] = {"string", "filename", "mode", "oldparser", "ast", NULL}; char *the_string; char *filename = "<string>"; char *mode_str = "exec"; int oldparser = 0; + int ast = 1; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ssp", keywords, - &the_string, &filename, &mode_str, &oldparser)) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|sspp", keywords, + &the_string, &filename, &mode_str, &oldparser, &ast)) { return NULL; } @@ -110,7 +111,14 @@ _Py_parse_string(PyObject *self, PyObject *args, PyObject *kwds) return NULL; } - PyObject *result = PyAST_mod2obj(mod); + PyObject *result; + if (ast) { + result = PyAST_mod2obj(mod); + } + else { + Py_INCREF(Py_None); + result = Py_None; + } PyArena_Free(arena); return result; } |