diff Modules/parsermodule.c @ 33166:2e8d2bdd33de legacy-trunk

This is Mark Russell's patch: [ 1009560 ] Fix @decorator evaluation order From the description: Changes in this patch: - Change Grammar/Grammar to require newlines between adjacent decorators. - Fix order of evaluation of decorators in the C (compile.c) and python (Lib/compiler/pycodegen.py) compilers - Add better order of evaluation check to test_decorators.py (test_eval_order) - Update the decorator documentation in the reference manual (improve description of evaluation order and update syntax description) and the comment: Used Brett's evaluation order (see http://mail.python.org/pipermail/python-dev/2004-August/047835.html) (I'm checking this in for Anthony who was having problems getting SF to talk to him)
author Michael W. Hudson <mwh@python.net>
date Tue, 17 Aug 2004 17:29:16 +0000
parents c7e03cf8333e
children f7474d31ba3f
line wrap: on
line diff
--- a/Modules/parsermodule.c	Tue Aug 17 16:37:12 2004 +0000
+++ b/Modules/parsermodule.c	Tue Aug 17 17:29:16 2004 +0000
@@ -2364,7 +2364,7 @@
 }
 
 /*  decorator:
- *    '@' dotted_name [ '(' [arglist] ')' ]
+ *    '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
  */
 static int
 validate_decorator(node *tree)
@@ -2372,41 +2372,37 @@
     int ok;
     int nch = NCH(tree);
     ok = (validate_ntype(tree, decorator) &&
-	  (nch == 2 || nch == 4 || nch == 5) &&
+	  (nch == 3 || nch == 5 || nch == 6) &&
 	  validate_at(CHILD(tree, 0)) &&
-	  validate_dotted_name(CHILD(tree, 1)));
-
-    if (ok && nch != 2) {
-	    ok = (validate_lparen(CHILD(tree, 2)) &&
-		  validate_rparen(RCHILD(tree, -1)));
-
-	    if (ok && nch == 5)
-		ok = validate_arglist(CHILD(tree, 3));
+	  validate_dotted_name(CHILD(tree, 1)) &&
+	  validate_newline(RCHILD(tree, -1)));
+
+    if (ok && nch != 3) {
+	ok = (validate_lparen(CHILD(tree, 2)) &&
+	      validate_rparen(RCHILD(tree, -2)));
+
+	if (ok && nch == 6)
+	    ok = validate_arglist(CHILD(tree, 3));
     }
 
     return ok;
 }
-    
+
 /*  decorators:
- *    decorator ([NEWLINE] decorator)* NEWLINE
+ *    decorator+
  */
 static int
 validate_decorators(node *tree)
 {
     int i, nch, ok; 
     nch = NCH(tree);
-    ok = validate_ntype(tree, decorators) && nch >= 2;
-
-    i = 0;
-    while (ok && i < nch - 1) {
+    ok = validate_ntype(tree, decorators) && nch >= 1;
+
+    for (i = 0; ok && i < nch; ++i)
 	ok = validate_decorator(CHILD(tree, i));
-	if (TYPE(CHILD(tree, i + 1)) == NEWLINE)
-	    ++i;
-	++i;
-    }
 
     return ok;
-}			       
+}
 
 /*  funcdef:
  *