Fix the grammar in PEP 3129.

This commit is contained in:
Collin Winter 2007-05-01 20:14:28 +00:00
parent 204b9762a8
commit 6b77a7f8e2
1 changed files with 17 additions and 5 deletions

View File

@ -65,13 +65,25 @@ For a detailed examination of decorators, please refer to PEP 318.
Implementation
==============
The grammar for class declarations changes from ::
Adapating Python's grammar to support class decorators requires
modifying two rules and adding a new rule ::
classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
to ::
funcdef: [decorators] 'def' NAME parameters ['->' test] ':' suite
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt |
with_stmt | funcdef | classdef
need to be changed to ::
decorated: decorators (classdef | funcdef)
classdef: [decorators] 'class' NAME ['(' [testlist] ')'] ':' suite
funcdef: 'def' NAME parameters ['->' test] ':' suite
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt |
with_stmt | funcdef | classdef | decorated
Adding ``decorated`` is necessary to avoid an ambiguity in the
grammar.
The Python AST and bytecode must be modified accordingly.