[Python-checkins] python/dist/src/Modules parsermodule.c,2.82,2.83

anthonybaxter at users.sourceforge.net anthonybaxter at users.sourceforge.net
Mon Aug 2 08:10:27 CEST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6086/Modules

Modified Files:
	parsermodule.c 
Log Message:
PEP-0318, @decorator-style. In Guido's words:
"@ seems the syntax that everybody can hate equally"
Implementation by Mark Russell, from SF #979728.


Index: parsermodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/parsermodule.c,v
retrieving revision 2.82
retrieving revision 2.83
diff -C2 -d -r2.82 -r2.83
*** parsermodule.c	19 May 2004 08:20:13 -0000	2.82
--- parsermodule.c	2 Aug 2004 06:09:55 -0000	2.83
***************
*** 825,828 ****
--- 825,829 ----
  #define validate_doublestar(ch) validate_terminal(ch, DOUBLESTAR, "**")
  #define validate_dot(ch)        validate_terminal(ch,        DOT, ".")
+ #define validate_at(ch)         validate_terminal(ch,         AT, "@")
  #define validate_name(ch, str)  validate_terminal(ch,       NAME, str)
  
***************
*** 2363,2380 ****
  }
  
  /*  funcdef:
!  *      'def' NAME parameters ':' suite
!  *
   */
  static int
  validate_funcdef(node *tree)
  {
!     return (validate_ntype(tree, funcdef)
!             && validate_numnodes(tree, 5, "funcdef")
!             && validate_name(CHILD(tree, 0), "def")
!             && validate_ntype(CHILD(tree, 1), NAME)
!             && validate_colon(CHILD(tree, 3))
!             && validate_parameters(CHILD(tree, 2))
!             && validate_suite(CHILD(tree, 4)));
  }
  
--- 2364,2433 ----
  }
  
+ /*  decorator:
+  *    '@' dotted_name [ '(' [arglist] ')' ]
+  */
+ static int
+ validate_decorator(node *tree)
+ {
+     int ok;
+     int nch = NCH(tree);
+     ok = (validate_ntype(tree, decorator) &&
+ 	  (nch == 2 || nch == 4 || nch == 5) &&
+ 	  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));
+     }
+ 
+     return ok;
+ }
+     
+ /*  decorators:
+  *    decorator ([NEWLINE] decorator)* NEWLINE
+  */
+ 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_decorator(CHILD(tree, i));
+ 	if (TYPE(CHILD(tree, i + 1)) == NEWLINE)
+ 	    ++i;
+ 	++i;
+     }
+ 
+     return ok;
+ }			       
+ 
  /*  funcdef:
!  *      
!  *            -6   -5    -4         -3  -2 -1
!  *  [decorators] 'def' NAME parameters ':' suite
   */
  static int
  validate_funcdef(node *tree)
  {
!     int nch = NCH(tree);
!     int ok = (validate_ntype(tree, funcdef)
! 	       && ((nch == 5) || (nch == 6))
! 	       && 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;
  }
  



More information about the Python-checkins mailing list