summaryrefslogtreecommitdiffstats
path: root/Modules/parsermodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r--Modules/parsermodule.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 5764c24..6e52343 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1498,7 +1498,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)
@@ -1517,7 +1517,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;
@@ -1527,7 +1528,6 @@ validate_compound_stmt(node *tree)
return (res);
}
-
static int
validate_yield_or_testlist(node *tree)
{
@@ -2558,28 +2558,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)
{
@@ -2923,6 +2935,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?)