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:
Thomas Wouters 2006-02-28 22:42:15 +00:00
parent 6cba25666c
commit 8ae1295c5b
5 changed files with 212 additions and 206 deletions

View File

@ -61,8 +61,8 @@ import_stmt: import_name | import_from
import_name: 'import' dotted_as_names
import_from: ('from' ('.'* dotted_name | '.')
'import' ('*' | '(' import_as_names ')' | import_as_names))
import_as_name: NAME [NAME NAME]
dotted_as_name: dotted_name [NAME NAME]
import_as_name: NAME [('as' | NAME) NAME]
dotted_as_name: dotted_name [('as' | NAME) NAME]
import_as_names: import_as_name (',' import_as_name)* [',']
dotted_as_names: dotted_as_name (',' dotted_as_name)*
dotted_name: NAME ('.' NAME)*
@ -80,7 +80,7 @@ try_stmt: ('try' ':' suite
['finally' ':' suite] |
'finally' ':' 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
except_clause: 'except' [test [',' test]]
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT

View File

@ -144,20 +144,22 @@ classify(parser_state *ps, int type, char *str)
register label *l = g->g_ll.ll_label;
register int i;
for (i = n; i > 0; i--, l++) {
if (l->lb_type == NAME && l->lb_str != NULL &&
l->lb_str[0] == s[0] &&
strcmp(l->lb_str, s) == 0) {
if (l->lb_type != NAME || l->lb_str == NULL ||
l->lb_str[0] != s[0] ||
strcmp(l->lb_str, s) != 0)
continue;
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT) &&
s[0] == 'w' &&
strcmp(s, "with") == 0)
break; /* not a 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 */
}
#endif
D(printf("It's a keyword\n"));
return n - i;
}
}
}
{
register label *l = g->g_ll.ll_label;

View File

@ -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)
warn(with_msg, err_ret->filename, tok->lineno);
else if (!(handling_import || handling_with) &&
len == 2 &&
str[0] == 'a' && strcmp(str, "as") == 0)
len == 2 && str[0] == 'a' &&
strcmp(str, "as") == 0)
warn(as_msg, err_ret->filename, tok->lineno);
}
else if (type == NAME &&

View File

@ -2088,8 +2088,8 @@ static alias_ty
alias_for_import_name(struct compiling *c, const node *n)
{
/*
import_as_name: NAME [NAME NAME]
dotted_as_name: dotted_name [NAME NAME]
import_as_name: NAME ['as' NAME]
dotted_as_name: dotted_name ['as' NAME]
dotted_name: NAME ('.' NAME)*
*/
PyObject *str;

File diff suppressed because it is too large Load Diff