diff options
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index f795088..8289173 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -1403,7 +1403,7 @@ validate_small_stmt(node *tree) /* 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) @@ -1422,7 +1422,8 @@ validate_compound_stmt(node *tree) || (ntype == for_stmt) || (ntype == try_stmt) || (ntype == funcdef) - || (ntype == classdef)) + || (ntype == classdef) + || (ntype == decorated)) res = validate_node(tree); else { res = 0; @@ -1432,7 +1433,6 @@ validate_compound_stmt(node *tree) return (res); } - static int validate_yield_or_testlist(node *tree) { @@ -2366,28 +2366,40 @@ validate_decorators(node *tree) /* 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) { @@ -2731,6 +2743,9 @@ validate_node(node *tree) case classdef: res = validate_class(tree); break; + case decorated: + res = validate_decorated(tree); + break; /* * "Trivial" parse tree nodes. * (Why did I call these trivial?) |