mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
This commit is contained in:
parent
4ed72acd68
commit
e3944a5e1e
13 changed files with 168 additions and 121 deletions
|
@ -149,6 +149,7 @@ classify(parser_state *ps, int type, char *str)
|
|||
strcmp(l->lb_str, s) != 0)
|
||||
continue;
|
||||
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
||||
#if 0
|
||||
/* Leaving this in as an example */
|
||||
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
|
||||
if (s[0] == 'w' && strcmp(s, "with") == 0)
|
||||
|
@ -156,6 +157,7 @@ classify(parser_state *ps, int type, char *str)
|
|||
else if (s[0] == 'a' && strcmp(s, "as") == 0)
|
||||
break; /* not a keyword yet */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
D(printf("It's a keyword\n"));
|
||||
return n - i;
|
||||
|
@ -178,6 +180,7 @@ classify(parser_state *ps, int type, char *str)
|
|||
}
|
||||
|
||||
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
||||
#if 0
|
||||
/* Leaving this in as an example */
|
||||
static void
|
||||
future_hack(parser_state *ps)
|
||||
|
@ -218,6 +221,7 @@ future_hack(parser_state *ps)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* future keyword */
|
||||
|
||||
int
|
||||
|
@ -278,10 +282,12 @@ PyParser_AddToken(register parser_state *ps, register int type, char *str,
|
|||
d->d_name,
|
||||
ps->p_stack.s_top->s_state));
|
||||
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
||||
#if 0
|
||||
if (d->d_name[0] == 'i' &&
|
||||
strcmp(d->d_name,
|
||||
"import_stmt") == 0)
|
||||
future_hack(ps);
|
||||
#endif
|
||||
#endif
|
||||
s_pop(&ps->p_stack);
|
||||
if (s_empty(&ps->p_stack)) {
|
||||
|
@ -296,9 +302,11 @@ PyParser_AddToken(register parser_state *ps, register int type, char *str,
|
|||
|
||||
if (s->s_accept) {
|
||||
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
||||
#if 0
|
||||
if (d->d_name[0] == 'i' &&
|
||||
strcmp(d->d_name, "import_stmt") == 0)
|
||||
future_hack(ps);
|
||||
#endif
|
||||
#endif
|
||||
/* Pop this dfa and try again */
|
||||
s_pop(&ps->p_stack);
|
||||
|
|
|
@ -100,6 +100,7 @@ PyParser_ParseFileFlagsEx(FILE *fp, const char *filename,
|
|||
}
|
||||
|
||||
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
||||
#if 0
|
||||
static char with_msg[] =
|
||||
"%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n";
|
||||
|
||||
|
@ -114,6 +115,7 @@ warn(const char *msg, const char *filename, int lineno)
|
|||
PySys_WriteStderr(msg, filename, lineno);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Parse input coming from the given tokenizer structure.
|
||||
Return error code. */
|
||||
|
@ -133,8 +135,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_BARRY_AS_BDFL)
|
||||
ps->p_flags |= CO_FUTURE_BARRY_AS_BDFL;
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
|
@ -177,26 +179,20 @@ 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);
|
||||
if (type == NOTEQUAL) {
|
||||
if (!(ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) &&
|
||||
strcmp(str, "!=")) {
|
||||
err_ret->error = E_SYNTAX;
|
||||
break;
|
||||
}
|
||||
else if ((ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) &&
|
||||
strcmp(str, "<>")) {
|
||||
err_ret->text = "with Barry as BDFL, use '<>' "
|
||||
"instead of '!='";
|
||||
err_ret->error = E_SYNTAX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
|
|
@ -1040,6 +1040,7 @@ PyToken_TwoChars(int c1, int c2)
|
|||
break;
|
||||
case '<':
|
||||
switch (c2) {
|
||||
case '>': return NOTEQUAL;
|
||||
case '=': return LESSEQUAL;
|
||||
case '<': return LEFTSHIFT;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue