summaryrefslogtreecommitdiffstats
path: root/Modules/_peg_parser.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-06 04:41:12 (GMT)
committerGitHub <noreply@github.com>2020-06-06 04:41:12 (GMT)
commit18f1226884e27d0cb89e7a2cc3d60a44df5da740 (patch)
tree10405fbad42c8b530a07862478bb34834d3a4970 /Modules/_peg_parser.c
parentd5e7348e4105d1d4a1c5bd1087f61041532ecbf3 (diff)
downloadcpython-18f1226884e27d0cb89e7a2cc3d60a44df5da740.zip
cpython-18f1226884e27d0cb89e7a2cc3d60a44df5da740.tar.gz
cpython-18f1226884e27d0cb89e7a2cc3d60a44df5da740.tar.bz2
Refactor scripts in Tools/peg_generator/scripts (GH-20401)
(cherry picked from commit ba6fd87e41dceb01dcdacc57c722aca12cde42a9) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Diffstat (limited to 'Modules/_peg_parser.c')
-rw-r--r--Modules/_peg_parser.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/_peg_parser.c b/Modules/_peg_parser.c
index b66d5a8..ca2a3cf 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;
}