1 #include "pegen_interface.h"
2
3 #include "../tokenizer.h"
4 #include "pegen.h"
5
6 mod_ty
PyPegen_ASTFromString(const char * str,const char * filename,int mode,PyCompilerFlags * flags,PyArena * arena)7 PyPegen_ASTFromString(const char *str, const char *filename, int mode,
8 PyCompilerFlags *flags, PyArena *arena)
9 {
10 PyObject *filename_ob = PyUnicode_FromString(filename);
11 if (filename_ob == NULL) {
12 return NULL;
13 }
14 mod_ty result = PyPegen_ASTFromStringObject(str, filename_ob, mode, flags, arena);
15 Py_XDECREF(filename_ob);
16 return result;
17 }
18
19 mod_ty
PyPegen_ASTFromStringObject(const char * str,PyObject * filename,int mode,PyCompilerFlags * flags,PyArena * arena)20 PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode,
21 PyCompilerFlags *flags, PyArena *arena)
22 {
23 if (PySys_Audit("compile", "yO", str, filename) < 0) {
24 return NULL;
25 }
26
27 mod_ty result = _PyPegen_run_parser_from_string(str, mode, filename, flags, arena);
28 return result;
29 }
30
31 mod_ty
PyPegen_ASTFromFilename(const char * filename,int mode,PyCompilerFlags * flags,PyArena * arena)32 PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena)
33 {
34 PyObject *filename_ob = PyUnicode_FromString(filename);
35 if (filename_ob == NULL) {
36 return NULL;
37 }
38
39 mod_ty result = _PyPegen_run_parser_from_file(filename, mode, filename_ob, flags, arena);
40 Py_XDECREF(filename_ob);
41 return result;
42 }
43
44 mod_ty
PyPegen_ASTFromFileObject(FILE * fp,PyObject * filename_ob,int mode,const char * enc,const char * ps1,const char * ps2,PyCompilerFlags * flags,int * errcode,PyArena * arena)45 PyPegen_ASTFromFileObject(FILE *fp, PyObject *filename_ob, int mode,
46 const char *enc, const char *ps1, const char* ps2,
47 PyCompilerFlags *flags, int *errcode, PyArena *arena)
48 {
49 if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) {
50 return NULL;
51 }
52 return _PyPegen_run_parser_from_file_pointer(fp, mode, filename_ob, enc, ps1, ps2,
53 flags, errcode, arena);
54 }
55