mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Disable the parser hacks that enabled the "yield" keyword using a future
statement.
This commit is contained in:
parent
12a6d942d8
commit
c24ea08644
5 changed files with 25 additions and 11 deletions
|
@ -17,7 +17,9 @@ typedef struct {
|
||||||
int expected;
|
int expected;
|
||||||
} perrdetail;
|
} perrdetail;
|
||||||
|
|
||||||
|
#if 0
|
||||||
#define PyPARSE_YIELD_IS_KEYWORD 0x0001
|
#define PyPARSE_YIELD_IS_KEYWORD 0x0001
|
||||||
|
#endif
|
||||||
|
|
||||||
extern DL_IMPORT(node *) PyParser_ParseString(char *, grammar *, int,
|
extern DL_IMPORT(node *) PyParser_ParseString(char *, grammar *, int,
|
||||||
perrdetail *);
|
perrdetail *);
|
||||||
|
|
|
@ -25,7 +25,9 @@ typedef struct {
|
||||||
stack p_stack; /* Stack of parser states */
|
stack p_stack; /* Stack of parser states */
|
||||||
grammar *p_grammar; /* Grammar to use */
|
grammar *p_grammar; /* Grammar to use */
|
||||||
node *p_tree; /* Top of parse tree */
|
node *p_tree; /* Top of parse tree */
|
||||||
|
#if 0 /* future keyword */
|
||||||
int p_generators; /* 1 if yield is a keyword */
|
int p_generators; /* 1 if yield is a keyword */
|
||||||
|
#endif
|
||||||
} parser_state;
|
} parser_state;
|
||||||
|
|
||||||
parser_state *PyParser_New(grammar *g, int start);
|
parser_state *PyParser_New(grammar *g, int start);
|
||||||
|
|
|
@ -83,8 +83,10 @@ PyParser_ParseFileFlags(FILE *fp, char *filename, grammar *g, int start,
|
||||||
/* Parse input coming from the given tokenizer structure.
|
/* Parse input coming from the given tokenizer structure.
|
||||||
Return error code. */
|
Return error code. */
|
||||||
|
|
||||||
|
#if 0 /* future keyword */
|
||||||
static char yield_msg[] =
|
static char yield_msg[] =
|
||||||
"%s:%d: Warning: 'yield' will become a reserved keyword in the future\n";
|
"%s:%d: Warning: 'yield' will become a reserved keyword in the future\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
static node *
|
static node *
|
||||||
parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
|
parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
|
||||||
|
@ -99,8 +101,10 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
|
||||||
err_ret->error = E_NOMEM;
|
err_ret->error = E_NOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#if 0 /* future keyword */
|
||||||
if (flags & PyPARSE_YIELD_IS_KEYWORD)
|
if (flags & PyPARSE_YIELD_IS_KEYWORD)
|
||||||
ps->p_generators = 1;
|
ps->p_generators = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char *a, *b;
|
char *a, *b;
|
||||||
|
@ -130,6 +134,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
|
||||||
strncpy(str, a, len);
|
strncpy(str, a, len);
|
||||||
str[len] = '\0';
|
str[len] = '\0';
|
||||||
|
|
||||||
|
#if 0 /* future keyword */
|
||||||
/* Warn about yield as NAME */
|
/* Warn about yield as NAME */
|
||||||
if (type == NAME && !ps->p_generators &&
|
if (type == NAME && !ps->p_generators &&
|
||||||
len == 5 && str[0] == 'y' && strcmp(str, "yield") == 0)
|
len == 5 && str[0] == 'y' && strcmp(str, "yield") == 0)
|
||||||
|
@ -137,6 +142,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
|
||||||
err_ret->filename==NULL ?
|
err_ret->filename==NULL ?
|
||||||
"<string>" : err_ret->filename,
|
"<string>" : err_ret->filename,
|
||||||
tok->lineno);
|
tok->lineno);
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((err_ret->error =
|
if ((err_ret->error =
|
||||||
PyParser_AddToken(ps, (int)type, str, tok->lineno,
|
PyParser_AddToken(ps, (int)type, str, tok->lineno,
|
||||||
|
|
|
@ -2984,10 +2984,12 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
|
||||||
result = 1;
|
result = 1;
|
||||||
cf->cf_flags |= compilerflags;
|
cf->cf_flags |= compilerflags;
|
||||||
}
|
}
|
||||||
|
#if 0 /* future keyword */
|
||||||
if (codeflags & CO_GENERATOR_ALLOWED) {
|
if (codeflags & CO_GENERATOR_ALLOWED) {
|
||||||
result = 1;
|
result = 1;
|
||||||
cf->cf_flags |= CO_GENERATOR_ALLOWED;
|
cf->cf_flags |= CO_GENERATOR_ALLOWED;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -542,6 +542,15 @@ PyRun_InteractiveOne(FILE *fp, char *filename)
|
||||||
return PyRun_InteractiveOneFlags(fp, filename, NULL);
|
return PyRun_InteractiveOneFlags(fp, filename, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* compute parser flags based on compiler flags */
|
||||||
|
#if 0 /* future keyword */
|
||||||
|
#define PARSER_FLAGS(flags) \
|
||||||
|
(((flags) && (flags)->cf_flags & CO_GENERATOR_ALLOWED) ? \
|
||||||
|
PyPARSE_YIELD_IS_KEYWORD : 0)
|
||||||
|
#else
|
||||||
|
#define PARSER_FLAGS(flags) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
PyRun_InteractiveOneFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
|
PyRun_InteractiveOneFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
|
||||||
{
|
{
|
||||||
|
@ -568,9 +577,7 @@ PyRun_InteractiveOneFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
|
||||||
}
|
}
|
||||||
n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
|
n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
|
||||||
Py_single_input, ps1, ps2, &err,
|
Py_single_input, ps1, ps2, &err,
|
||||||
(flags &&
|
PARSER_FLAGS(flags));
|
||||||
flags->cf_flags & CO_GENERATOR_ALLOWED) ?
|
|
||||||
PyPARSE_YIELD_IS_KEYWORD : 0);
|
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
Py_XDECREF(w);
|
Py_XDECREF(w);
|
||||||
if (n == NULL) {
|
if (n == NULL) {
|
||||||
|
@ -1031,9 +1038,7 @@ PyRun_StringFlags(char *str, int start, PyObject *globals, PyObject *locals,
|
||||||
PyCompilerFlags *flags)
|
PyCompilerFlags *flags)
|
||||||
{
|
{
|
||||||
return run_err_node(PyParser_SimpleParseStringFlags(
|
return run_err_node(PyParser_SimpleParseStringFlags(
|
||||||
str, start,
|
str, start, PARSER_FLAGS(flags)),
|
||||||
(flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
|
|
||||||
PyPARSE_YIELD_IS_KEYWORD : 0),
|
|
||||||
"<string>", globals, locals, flags);
|
"<string>", globals, locals, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1050,8 +1055,7 @@ PyRun_FileExFlags(FILE *fp, char *filename, int start, PyObject *globals,
|
||||||
PyObject *locals, int closeit, PyCompilerFlags *flags)
|
PyObject *locals, int closeit, PyCompilerFlags *flags)
|
||||||
{
|
{
|
||||||
node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
|
node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
|
||||||
(flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
|
PARSER_FLAGS(flags));
|
||||||
PyPARSE_YIELD_IS_KEYWORD : 0);
|
|
||||||
if (closeit)
|
if (closeit)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return run_err_node(n, filename, globals, locals, flags);
|
return run_err_node(n, filename, globals, locals, flags);
|
||||||
|
@ -1125,9 +1129,7 @@ Py_CompileStringFlags(char *str, char *filename, int start,
|
||||||
{
|
{
|
||||||
node *n;
|
node *n;
|
||||||
PyCodeObject *co;
|
PyCodeObject *co;
|
||||||
n = PyParser_SimpleParseStringFlags(str, start,
|
n = PyParser_SimpleParseStringFlags(str, start, PARSER_FLAGS(flags));
|
||||||
(flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
|
|
||||||
PyPARSE_YIELD_IS_KEYWORD : 0);
|
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
co = PyNode_CompileFlags(n, filename, flags);
|
co = PyNode_CompileFlags(n, filename, flags);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue