summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-07-16 05:37:24 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-07-16 05:37:24 (GMT)
commitfe2127d3cbf34452a10b88c40e5ab06870936f94 (patch)
treef8dc5d80679d9003646e666f1f3d9253f7ae13bb /Python
parente75785a646d2cb4004187772f1df3bc5d474a77f (diff)
downloadcpython-fe2127d3cbf34452a10b88c40e5ab06870936f94.zip
cpython-fe2127d3cbf34452a10b88c40e5ab06870936f94.tar.gz
cpython-fe2127d3cbf34452a10b88c40e5ab06870936f94.tar.bz2
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
that 'yield' is a keyword. This doesn't help test_generators at all! I don't know why not. These things do work now (and didn't before this patch): 1. "from __future__ import generators" now works in a native shell. 2. Similarly "python -i xxx.py" now has generators enabled in the shell if xxx.py had them enabled. 3. This program (which was my doctest proxy) works fine: from __future__ import generators source = """\ def f(): yield 1 """ exec compile(source, "", "single") in globals() print type(f())
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 0412b7e..1d20deb 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -533,6 +533,7 @@ PyRun_InteractiveOneFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
node *n;
perrdetail err;
char *ps1 = "", *ps2 = "";
+
v = PySys_GetObject("ps1");
if (v != NULL) {
v = PyObject_Str(v);
@@ -549,8 +550,11 @@ PyRun_InteractiveOneFlags(FILE *fp, char *filename, PyCompilerFlags *flags)
else if (PyString_Check(w))
ps2 = PyString_AsString(w);
}
- n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,
- Py_single_input, ps1, ps2, &err);
+ n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
+ Py_single_input, ps1, ps2, &err,
+ (flags &&
+ flags->cf_flags & PyCF_GENERATORS) ?
+ PyPARSE_YIELD_IS_KEYWORD : 0);
Py_XDECREF(v);
Py_XDECREF(w);
if (n == NULL) {
@@ -1017,7 +1021,9 @@ PyObject *
PyRun_FileExFlags(FILE *fp, char *filename, int start, PyObject *globals,
PyObject *locals, int closeit, PyCompilerFlags *flags)
{
- node *n = PyParser_SimpleParseFile(fp, filename, start);
+ node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
+ (flags && flags->cf_flags & PyCF_GENERATORS) ?
+ PyPARSE_YIELD_IS_KEYWORD : 0);
if (closeit)
fclose(fp);
return run_err_node(n, filename, globals, locals, flags);
@@ -1101,7 +1107,9 @@ Py_CompileStringFlags(char *str, char *filename, int start,
{
node *n;
PyCodeObject *co;
- n = PyParser_SimpleParseString(str, start);
+ n = PyParser_SimpleParseStringFlags(str, start,
+ (flags && flags->cf_flags & PyCF_GENERATORS) ?
+ PyPARSE_YIELD_IS_KEYWORD : 0);
if (n == NULL)
return NULL;
co = PyNode_CompileFlags(n, filename, flags);
@@ -1125,30 +1133,43 @@ Py_SymtableString(char *str, char *filename, int start)
/* Simplified interface to parsefile -- return node or set exception */
node *
-PyParser_SimpleParseFile(FILE *fp, char *filename, int start)
+PyParser_SimpleParseFileFlags(FILE *fp, char *filename, int start, int flags)
{
node *n;
perrdetail err;
- n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar, start,
- (char *)0, (char *)0, &err);
+ n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, start,
+ (char *)0, (char *)0, &err, flags);
if (n == NULL)
err_input(&err);
return n;
}
+node *
+PyParser_SimpleParseFile(FILE *fp, char *filename, int start)
+{
+ return PyParser_SimpleParseFileFlags(fp, filename, start, 0);
+}
+
/* Simplified interface to parsestring -- return node or set exception */
node *
-PyParser_SimpleParseString(char *str, int start)
+PyParser_SimpleParseStringFlags(char *str, int start, int flags)
{
node *n;
perrdetail err;
- n = PyParser_ParseString(str, &_PyParser_Grammar, start, &err);
+ n = PyParser_ParseStringFlags(str, &_PyParser_Grammar, start, &err,
+ flags);
if (n == NULL)
err_input(&err);
return n;
}
+node *
+PyParser_SimpleParseString(char *str, int start)
+{
+ return PyParser_SimpleParseStringFlags(str, start, 0);
+}
+
/* Set the error appropriate to the given input error code (see errcode.h) */
static void