Example #1
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;
}
Example #2
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;
}
Example #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;
}
Example #4
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;
	}
}
Example #5
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;
	}
}