mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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.
This commit is contained in:
parent
6c0ff8aacd
commit
7c47894a2a
13 changed files with 238 additions and 34 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue