mirror of https://github.com/python/cpython
Make 'as' an actual keyword when with's future statement is used. Not
actually necessary for functionality, but good for transition.
This commit is contained in:
parent
6cba25666c
commit
8ae1295c5b
|
@ -61,8 +61,8 @@ import_stmt: import_name | import_from
|
||||||
import_name: 'import' dotted_as_names
|
import_name: 'import' dotted_as_names
|
||||||
import_from: ('from' ('.'* dotted_name | '.')
|
import_from: ('from' ('.'* dotted_name | '.')
|
||||||
'import' ('*' | '(' import_as_names ')' | import_as_names))
|
'import' ('*' | '(' import_as_names ')' | import_as_names))
|
||||||
import_as_name: NAME [NAME NAME]
|
import_as_name: NAME [('as' | NAME) NAME]
|
||||||
dotted_as_name: dotted_name [NAME NAME]
|
dotted_as_name: dotted_name [('as' | NAME) NAME]
|
||||||
import_as_names: import_as_name (',' import_as_name)* [',']
|
import_as_names: import_as_name (',' import_as_name)* [',']
|
||||||
dotted_as_names: dotted_as_name (',' dotted_as_name)*
|
dotted_as_names: dotted_as_name (',' dotted_as_name)*
|
||||||
dotted_name: NAME ('.' NAME)*
|
dotted_name: NAME ('.' NAME)*
|
||||||
|
@ -80,7 +80,7 @@ try_stmt: ('try' ':' suite
|
||||||
['finally' ':' suite] |
|
['finally' ':' suite] |
|
||||||
'finally' ':' suite))
|
'finally' ':' suite))
|
||||||
with_stmt: 'with' test [ with_var ] ':' suite
|
with_stmt: 'with' test [ with_var ] ':' suite
|
||||||
with_var: NAME expr
|
with_var: ('as' | NAME) expr
|
||||||
# NB compile.c makes sure that the default except clause is last
|
# NB compile.c makes sure that the default except clause is last
|
||||||
except_clause: 'except' [test [',' test]]
|
except_clause: 'except' [test [',' test]]
|
||||||
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
|
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
|
||||||
|
|
|
@ -144,18 +144,20 @@ classify(parser_state *ps, int type, char *str)
|
||||||
register label *l = g->g_ll.ll_label;
|
register label *l = g->g_ll.ll_label;
|
||||||
register int i;
|
register int i;
|
||||||
for (i = n; i > 0; i--, l++) {
|
for (i = n; i > 0; i--, l++) {
|
||||||
if (l->lb_type == NAME && l->lb_str != NULL &&
|
if (l->lb_type != NAME || l->lb_str == NULL ||
|
||||||
l->lb_str[0] == s[0] &&
|
l->lb_str[0] != s[0] ||
|
||||||
strcmp(l->lb_str, s) == 0) {
|
strcmp(l->lb_str, s) != 0)
|
||||||
|
continue;
|
||||||
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
||||||
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT) &&
|
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
|
||||||
s[0] == 'w' &&
|
if (s[0] == 'w' && strcmp(s, "with") == 0)
|
||||||
strcmp(s, "with") == 0)
|
break; /* not a keyword yet */
|
||||||
break; /* not a keyword */
|
else if (s[0] == 'a' && strcmp(s, "as") == 0)
|
||||||
#endif
|
break; /* not a keyword yet */
|
||||||
D(printf("It's a keyword\n"));
|
|
||||||
return n - i;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
D(printf("It's a keyword\n"));
|
||||||
|
return n - i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
|
||||||
if (len == 4 && str[0] == 'w' && strcmp(str, "with") == 0)
|
if (len == 4 && str[0] == 'w' && strcmp(str, "with") == 0)
|
||||||
warn(with_msg, err_ret->filename, tok->lineno);
|
warn(with_msg, err_ret->filename, tok->lineno);
|
||||||
else if (!(handling_import || handling_with) &&
|
else if (!(handling_import || handling_with) &&
|
||||||
len == 2 &&
|
len == 2 && str[0] == 'a' &&
|
||||||
str[0] == 'a' && strcmp(str, "as") == 0)
|
strcmp(str, "as") == 0)
|
||||||
warn(as_msg, err_ret->filename, tok->lineno);
|
warn(as_msg, err_ret->filename, tok->lineno);
|
||||||
}
|
}
|
||||||
else if (type == NAME &&
|
else if (type == NAME &&
|
||||||
|
|
|
@ -2088,8 +2088,8 @@ static alias_ty
|
||||||
alias_for_import_name(struct compiling *c, const node *n)
|
alias_for_import_name(struct compiling *c, const node *n)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
import_as_name: NAME [NAME NAME]
|
import_as_name: NAME ['as' NAME]
|
||||||
dotted_as_name: dotted_name [NAME NAME]
|
dotted_as_name: dotted_name ['as' NAME]
|
||||||
dotted_name: NAME ('.' NAME)*
|
dotted_name: NAME ('.' NAME)*
|
||||||
*/
|
*/
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue