Mercurial > cpython-lru_cache-weakref
diff Modules/parsermodule.c @ 45447:393822f2ef90 legacy-trunk
Patch #1759: Backport of PEP 3129 class decorators
with some help from Georg
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Sat, 23 Feb 2008 15:01:05 +0000 |
| parents | 0cbe94bea2c7 |
| children | b40827eb4b80 |
line wrap: on
line diff
--- a/Modules/parsermodule.c Sat Feb 23 12:46:10 2008 +0000 +++ b/Modules/parsermodule.c Sat Feb 23 15:01:05 2008 +0000 @@ -1498,7 +1498,7 @@ /* compound_stmt: - * if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef + * if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef | decorated */ static int validate_compound_stmt(node *tree) @@ -1517,7 +1517,8 @@ || (ntype == for_stmt) || (ntype == try_stmt) || (ntype == funcdef) - || (ntype == classdef)) + || (ntype == classdef) + || (ntype == decorated)) res = validate_node(tree); else { res = 0; @@ -1527,7 +1528,6 @@ return (res); } - static int validate_yield_or_testlist(node *tree) { @@ -2558,28 +2558,40 @@ /* funcdef: * - * -6 -5 -4 -3 -2 -1 - * [decorators] 'def' NAME parameters ':' suite + * -5 -4 -3 -2 -1 + * 'def' NAME parameters ':' suite */ static int validate_funcdef(node *tree) { int nch = NCH(tree); int ok = (validate_ntype(tree, funcdef) - && ((nch == 5) || (nch == 6)) + && (nch == 5) && validate_name(RCHILD(tree, -5), "def") && validate_ntype(RCHILD(tree, -4), NAME) && validate_colon(RCHILD(tree, -2)) && validate_parameters(RCHILD(tree, -3)) && validate_suite(RCHILD(tree, -1))); - - if (ok && (nch == 6)) - ok = validate_decorators(CHILD(tree, 0)); - return ok; } +/* decorated + * decorators (classdef | funcdef) + */ +static int +validate_decorated(node *tree) +{ + int nch = NCH(tree); + int ok = (validate_ntype(tree, decorated) + && (nch == 2) + && validate_decorators(RCHILD(tree, -2)) + && (validate_funcdef(RCHILD(tree, -1)) + || validate_class(RCHILD(tree, -1))) + ); + return ok; +} + static int validate_lambdef(node *tree) { @@ -2923,6 +2935,9 @@ case classdef: res = validate_class(tree); break; + case decorated: + res = validate_decorated(tree); + break; /* * "Trivial" parse tree nodes. * (Why did I call these trivial?)
