diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-03-01 23:34:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-01 23:34:44 (GMT) |
commit | 1f24a719e7be5e49b876a5dc7daf21d01ee69faa (patch) | |
tree | 8f8f56cab78ef671a8cb7f54b8ec2495d9a435e6 /Parser/parsetok.c | |
parent | 7eebbbd5b3907447eddadf5cb7cb1cc9230d15b2 (diff) | |
download | cpython-1f24a719e7be5e49b876a5dc7daf21d01ee69faa.zip cpython-1f24a719e7be5e49b876a5dc7daf21d01ee69faa.tar.gz cpython-1f24a719e7be5e49b876a5dc7daf21d01ee69faa.tar.bz2 |
bpo-35808: Retire pgen and use pgen2 to generate the parser (GH-11814)
Pgen is the oldest piece of technology in the CPython repository, building it requires various #if[n]def PGEN hacks in other parts of the code and it also depends more and more on CPython internals. This commit removes the old pgen C code and replaces it for a new version implemented in pure Python. This is a modified and adapted version of lib2to3/pgen2 that can generate grammar files compatibles with the current parser.
This commit also eliminates all the #ifdef and code branches related to pgen, simplifying the code and making it more maintainable. The regen-grammar step now uses $(PYTHON_FOR_REGEN) that can be any version of the interpreter, so the new pgen code maintains compatibility with older versions of the interpreter (this also allows regenerating the grammar with the current CI solution that uses Python3.5). The new pgen Python module also makes use of the Grammar/Tokens file that holds the token specification, so is always kept in sync and avoids having to maintain duplicate token definitions.
Diffstat (limited to 'Parser/parsetok.c')
-rw-r--r-- | Parser/parsetok.c | 16 |
1 files changed, 0 insertions, 16 deletions
diff --git a/Parser/parsetok.c b/Parser/parsetok.c index 6a96f6b..7a6c886 100644 --- a/Parser/parsetok.c +++ b/Parser/parsetok.c @@ -99,10 +99,8 @@ PyParser_ParseStringObject(const char *s, PyObject *filename, tok->type_comments = 1; } -#ifndef PGEN Py_INCREF(err_ret->filename); tok->filename = err_ret->filename; -#endif return parsetok(tok, g, start, err_ret, flags); } @@ -113,7 +111,6 @@ PyParser_ParseStringFlagsFilenameEx(const char *s, const char *filename_str, { node *n; PyObject *filename = NULL; -#ifndef PGEN if (filename_str != NULL) { filename = PyUnicode_DecodeFSDefault(filename_str); if (filename == NULL) { @@ -121,11 +118,8 @@ PyParser_ParseStringFlagsFilenameEx(const char *s, const char *filename_str, return NULL; } } -#endif n = PyParser_ParseStringObject(s, filename, g, start, err_ret, flags); -#ifndef PGEN Py_XDECREF(filename); -#endif return n; } @@ -169,10 +163,8 @@ PyParser_ParseFileObject(FILE *fp, PyObject *filename, if (*flags & PyPARSE_TYPE_COMMENTS) { tok->type_comments = 1; } -#ifndef PGEN Py_INCREF(err_ret->filename); tok->filename = err_ret->filename; -#endif return parsetok(tok, g, start, err_ret, flags); } @@ -184,7 +176,6 @@ PyParser_ParseFileFlagsEx(FILE *fp, const char *filename, { node *n; PyObject *fileobj = NULL; -#ifndef PGEN if (filename != NULL) { fileobj = PyUnicode_DecodeFSDefault(filename); if (fileobj == NULL) { @@ -192,12 +183,9 @@ PyParser_ParseFileFlagsEx(FILE *fp, const char *filename, return NULL; } } -#endif n = PyParser_ParseFileObject(fp, fileobj, enc, g, start, ps1, ps2, err_ret, flags); -#ifndef PGEN Py_XDECREF(fileobj); -#endif return n; } @@ -371,7 +359,6 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, } } -#ifndef PGEN /* Check that the source for a single input statement really is a single statement by looking at what is left in the buffer after parsing. Trailing whitespace and comments @@ -399,7 +386,6 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, c = *++cur; } } -#endif } else n = NULL; @@ -470,7 +456,6 @@ initerr(perrdetail *err_ret, PyObject *filename) err_ret->text = NULL; err_ret->token = -1; err_ret->expected = -1; -#ifndef PGEN if (filename) { Py_INCREF(filename); err_ret->filename = filename; @@ -482,6 +467,5 @@ initerr(perrdetail *err_ret, PyObject *filename) return -1; } } -#endif return 0; } |