Пример #1
0
/* Preferred access to parser is through AST. */
mod_ty
PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start,
                             PyCompilerFlags *flags, PyArena *arena)
{
    mod_ty mod;
    PyCompilerFlags localflags;
    perrdetail err;
    int iflags = PARSER_FLAGS(flags);

    node *n = PyParser_ParseStringObject(s, filename,
                                         &_PyParser_Grammar, start, &err,
                                         &iflags);
    if (flags == NULL) {
        localflags.cf_flags = 0;
        flags = &localflags;
    }
    if (n) {
        flags->cf_flags |= iflags & PyCF_MASK;
        mod = PyAST_FromNodeObject(n, flags, filename, arena);
        PyNode_Free(n);
    }
    else {
        err_input(&err);
        mod = NULL;
    }
    err_free(&err);
    return mod;
}
Пример #2
0
mod_ty
PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc,
                           int start, const char *ps1,
                           const char *ps2, PyCompilerFlags *flags, int *errcode,
                           PyArena *arena)
{
    mod_ty mod;
    PyCompilerFlags localflags;
    perrdetail err;
    int iflags = PARSER_FLAGS(flags);

    node *n = PyParser_ParseFileObject(fp, filename, enc,
                                       &_PyParser_Grammar,
                                       start, ps1, ps2, &err, &iflags);
    if (flags == NULL) {
        localflags.cf_flags = 0;
        flags = &localflags;
    }
    if (n) {
        flags->cf_flags |= iflags & PyCF_MASK;
        mod = PyAST_FromNodeObject(n, flags, filename, arena);
        PyNode_Free(n);
    }
    else {
        err_input(&err);
        if (errcode)
            *errcode = err.error;
        mod = NULL;
    }
    err_free(&err);
    return mod;
}
Пример #3
0
/* Preferred access to parser is through AST. */
static mod_ty
string_object_to_c_ast(const char *s, PyObject *filename, int start,
                             PyCompilerFlags *flags, PyArena *arena)
{
    mod_ty mod;
    PyCompilerFlags localflags;
    perrdetail err;
    int iflags = PARSER_FLAGS(flags);

    node *n = Ta27Parser_ParseStringObject(s, filename,
                                         &_Ta27Parser_Grammar, start, &err,
                                         &iflags);
    if (flags == NULL) {
        localflags.cf_flags = 0;
        flags = &localflags;
    }
    if (n) {
        flags->cf_flags |= iflags & PyCF_MASK;
        mod = Ta27AST_FromNode(n, flags, PyUnicode_AsUTF8(filename), arena);
        Ta27Node_Free(n);
    }
    else {
        err_input(&err);
        mod = NULL;
    }
    err_free(&err);
    return mod;
}
Пример #4
0
node *
PyParser_SimpleParseString(char *str, int start)
{
	node *n;
	perrdetail err;
	n = PyParser_ParseString(str, &_PyParser_Grammar, start, &err);
	if (n == NULL)
		err_input(&err);
	return n;
}
Пример #5
0
node *
PyParser_SimpleParseStringFlags(const char *str, int start, int flags)
{
	perrdetail err;
	node *n = PyParser_ParseStringFlags(str, &_PyParser_Grammar,
					    start, &err, flags);
	if (n == NULL)
		err_input(&err);
	return n;
}
Пример #6
0
node *
PyParser_SimpleParseFile(FILE *fp, char *filename, int start)
{
	node *n;
	perrdetail err;
	n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar, start,
				(char *)0, (char *)0, &err);
	if (n == NULL)
		err_input(&err);
	return n;
}
Пример #7
0
node *
PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags)
{
	perrdetail err;
	node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
					  start, NULL, NULL, &err, flags);
	if (n == NULL)
		err_input(&err);

	return n;
}
Пример #8
0
int
PyRun_InteractiveOne(FILE *fp, char *filename)
{
	PyObject *m, *d, *v, *w;
	node *n;
	perrdetail err;
	char *ps1 = "", *ps2 = "";
	v = PySys_GetObject("ps1");
	if (v != NULL) {
		v = PyObject_Str(v);
		if (v == NULL)
			PyErr_Clear();
		else if (PyString_Check(v))
			ps1 = PyString_AsString(v);
	}
	w = PySys_GetObject("ps2");
	if (w != NULL) {
		w = PyObject_Str(w);
		if (w == NULL)
			PyErr_Clear();
		else if (PyString_Check(w))
			ps2 = PyString_AsString(w);
	}
	n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,
			       Py_single_input, ps1, ps2, &err);
	Py_XDECREF(v);
	Py_XDECREF(w);
	if (n == NULL) {
		if (err.error == E_EOF) {
			if (err.text)
				PyMem_DEL(err.text);
			return E_EOF;
		}
		err_input(&err);
		PyErr_Print();
		return err.error;
	}
	m = PyImport_AddModule("__main__");
	if (m == NULL)
		return -1;
	d = PyModule_GetDict(m);
	v = run_node(n, filename, d, d);
	if (v == NULL) {
		PyErr_Print();
		return -1;
	}
	Py_DECREF(v);
	if (Py_FlushLine())
		PyErr_Clear();
	return 0;
}
Пример #9
0
/* Preferred access to parser is through AST. */
mod_ty
PyParser_ASTFromString(const char *s, const char *filename, int start,
		       PyCompilerFlags *flags, PyArena *arena)
{
	mod_ty mod;
	perrdetail err;
	node *n = PyParser_ParseStringFlagsFilename(s, filename,
					&_PyParser_Grammar, start, &err,
					PARSER_FLAGS(flags));
	if (n) {
		mod = PyAST_FromNode(n, flags, filename, arena);
		PyNode_Free(n);
		return mod;
	}
	else {
		err_input(&err);
		return NULL;
	}
}
Пример #10
0
mod_ty
PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1,
		     char *ps2, PyCompilerFlags *flags, int *errcode,
		     PyArena *arena)
{
	mod_ty mod;
	perrdetail err;
	node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
				start, ps1, ps2, &err, PARSER_FLAGS(flags));
	if (n) {
		mod = PyAST_FromNode(n, flags, filename, arena);
		PyNode_Free(n);
		return mod;
	}
	else {
		err_input(&err);
		if (errcode)
			*errcode = err.error;
		return NULL;
	}
}
Пример #11
0
void
PyParser_SetError(perrdetail *err)
{
    err_input(err);
}