summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2008-03-18 23:45:49 (GMT)
committerEric Smith <eric@trueblade.com>2008-03-18 23:45:49 (GMT)
commit7c47894a2aaa8dbc5397a256b16cd7deddef1d7e (patch)
tree8a04cef2a98907c1f20cde46f0efec77a5730a65 /Parser
parent6c0ff8aacd5b493892878e138b97af66e4bfaf37 (diff)
downloadcpython-7c47894a2aaa8dbc5397a256b16cd7deddef1d7e.zip
cpython-7c47894a2aaa8dbc5397a256b16cd7deddef1d7e.tar.gz
cpython-7c47894a2aaa8dbc5397a256b16cd7deddef1d7e.tar.bz2
Backport of the print function, using a __future__ import.
This work is substantially Anthony Baxter's, from issue 1633807. I just freshened it, made a few minor tweaks, and added the test cases. I also created issue 2412, which is to check for 2to3's behavior with the print function. I also added myself to ACKS.
Diffstat (limited to 'Parser')
-rw-r--r--Parser/parser.c14
-rw-r--r--Parser/parsetok.c24
2 files changed, 10 insertions, 28 deletions
diff --git a/Parser/parser.c b/Parser/parser.c
index 2ce84cd..61da37d 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -149,12 +149,10 @@ classify(parser_state *ps, int type, char *str)
strcmp(l->lb_str, s) != 0)
continue;
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
- if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
- if (s[0] == 'w' && strcmp(s, "with") == 0)
- break; /* not a keyword yet */
- else if (s[0] == 'a' && strcmp(s, "as") == 0)
- break; /* not a keyword yet */
- }
+ if (ps->p_flags & CO_FUTURE_PRINT_FUNCTION &&
+ s[0] == 'p' && strcmp(s, "print") == 0) {
+ break; /* no longer a keyword */
+ }
#endif
D(printf("It's a keyword\n"));
return n - i;
@@ -208,6 +206,10 @@ future_hack(parser_state *ps)
strcmp(STR(CHILD(cch, 0)), "with_statement") == 0) {
ps->p_flags |= CO_FUTURE_WITH_STATEMENT;
break;
+ } else if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME &&
+ strcmp(STR(CHILD(cch, 0)), "print_function") == 0) {
+ ps->p_flags |= CO_FUTURE_PRINT_FUNCTION;
+ break;
}
}
}
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index f3d8462..e4db574 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -123,8 +123,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
return NULL;
}
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
- if (flags & PyPARSE_WITH_IS_KEYWORD)
- ps->p_flags |= CO_FUTURE_WITH_STATEMENT;
+ if (flags & PyPARSE_PRINT_IS_FUNCTION)
+ ps->p_flags |= CO_FUTURE_PRINT_FUNCTION;
#endif
for (;;) {
@@ -167,26 +167,6 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
str[len] = '\0';
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
- /* This is only necessary to support the "as" warning, but
- we don't want to warn about "as" in import statements. */
- if (type == NAME &&
- len == 6 && str[0] == 'i' && strcmp(str, "import") == 0)
- handling_import = 1;
-
- /* Warn about with as NAME */
- if (type == NAME &&
- !(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
- if (len == 4 && str[0] == 'w' && strcmp(str, "with") == 0)
- warn(with_msg, err_ret->filename, tok->lineno);
- else if (!(handling_import || handling_with) &&
- len == 2 && str[0] == 'a' &&
- strcmp(str, "as") == 0)
- warn(as_msg, err_ret->filename, tok->lineno);
- }
- else if (type == NAME &&
- (ps->p_flags & CO_FUTURE_WITH_STATEMENT) &&
- len == 4 && str[0] == 'w' && strcmp(str, "with") == 0)
- handling_with = 1;
#endif
if (a >= tok->line_start)
col_offset = a - tok->line_start;