diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-13 09:25:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-13 09:25:37 (GMT) |
commit | e1d8c65e1df990ef8d61b8912742e1a021395e78 (patch) | |
tree | 84956c1158b3baf33d9836a5a87b8fa6b57a0428 /Parser | |
parent | 898f531996f2c5399b13811682c578c4fd08afaa (diff) | |
download | cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.zip cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.tar.gz cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.tar.bz2 |
gh-110805: Allow the repl to show source code and complete tracebacks (#110775)
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/peg_api.c | 15 | ||||
-rw-r--r-- | Parser/pegen.c | 12 | ||||
-rw-r--r-- | Parser/pegen.h | 3 |
3 files changed, 27 insertions, 3 deletions
diff --git a/Parser/peg_api.c b/Parser/peg_api.c index 447f566..d4acc3e 100644 --- a/Parser/peg_api.c +++ b/Parser/peg_api.c @@ -23,5 +23,18 @@ _PyParser_ASTFromFile(FILE *fp, PyObject *filename_ob, const char *enc, return NULL; } return _PyPegen_run_parser_from_file_pointer(fp, mode, filename_ob, enc, ps1, ps2, - flags, errcode, arena); + flags, errcode, NULL, arena); } + +mod_ty +_PyParser_InteractiveASTFromFile(FILE *fp, PyObject *filename_ob, const char *enc, + int mode, const char *ps1, const char* ps2, + PyCompilerFlags *flags, int *errcode, + PyObject **interactive_src, PyArena *arena) +{ + if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) { + return NULL; + } + return _PyPegen_run_parser_from_file_pointer(fp, mode, filename_ob, enc, ps1, ps2, + flags, errcode, interactive_src, arena); +}
\ No newline at end of file diff --git a/Parser/pegen.c b/Parser/pegen.c index 2e0b569..0c60394 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -878,7 +878,8 @@ _PyPegen_run_parser(Parser *p) mod_ty _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filename_ob, const char *enc, const char *ps1, const char *ps2, - PyCompilerFlags *flags, int *errcode, PyArena *arena) + PyCompilerFlags *flags, int *errcode, + PyObject **interactive_src, PyArena *arena) { struct tok_state *tok = _PyTokenizer_FromFile(fp, enc, ps1, ps2); if (tok == NULL) { @@ -908,6 +909,15 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filena result = _PyPegen_run_parser(p); _PyPegen_Parser_Free(p); + if (tok->fp_interactive && tok->interactive_src_start && result && interactive_src != NULL) { + *interactive_src = PyUnicode_FromString(tok->interactive_src_start); + if (!interactive_src || _PyArena_AddPyObject(arena, *interactive_src) < 0) { + Py_XDECREF(interactive_src); + result = NULL; + goto error; + } + } + error: _PyTokenizer_Free(tok); return result; diff --git a/Parser/pegen.h b/Parser/pegen.h index 266d521..424f80a 100644 --- a/Parser/pegen.h +++ b/Parser/pegen.h @@ -350,7 +350,8 @@ void *_PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args, asdl_comprehensi Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *); void _PyPegen_Parser_Free(Parser *); mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *, - const char *, const char *, PyCompilerFlags *, int *, PyArena *); + const char *, const char *, PyCompilerFlags *, int *, PyObject **, + PyArena *); void *_PyPegen_run_parser(Parser *); mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *); asdl_stmt_seq *_PyPegen_interactive_exit(Parser *); |