[Python-checkins] CVS: python/dist/src/Modules parsermodule.c,2.52,2.53

Fred L. Drake python-dev@python.org
Fri, 25 Aug 2000 15:42:43 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv25671/Modules

Modified Files:
	parsermodule.c 
Log Message:

Update the parser module to support augmented assignment.

Add some test cases.


Index: parsermodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/parsermodule.c,v
retrieving revision 2.52
retrieving revision 2.53
diff -C2 -r2.52 -r2.53
*** parsermodule.c	2000/08/23 15:35:26	2.52
--- parsermodule.c	2000/08/25 22:42:40	2.53
***************
*** 1468,1475 ****
                 && validate_testlist(CHILD(tree, 0)));
  
!     for (j = 1; res && (j < nch); j += 2)
!         res = (validate_equal(CHILD(tree, j))
!                && validate_testlist(CHILD(tree, j + 1)));
  
      return (res);
  }
--- 1468,1499 ----
                 && validate_testlist(CHILD(tree, 0)));
  
!     if (res && nch == 3
!         && TYPE(CHILD(tree, 1)) == augassign) {
!         res = (validate_numnodes(CHILD(tree, 1), 1, "augassign")
!                && validate_testlist(CHILD(tree, 2)));
  
+         if (res) {
+             char *s = STR(CHILD(CHILD(tree, 1), 0));
+ 
+             res = (strcmp(s, "+=") == 0
+                    || strcmp(s, "-=") == 0
+                    || strcmp(s, "*=") == 0
+                    || strcmp(s, "/=") == 0
+                    || strcmp(s, "%=") == 0
+                    || strcmp(s, "&=") == 0
+                    || strcmp(s, "|=") == 0
+                    || strcmp(s, "^=") == 0
+                    || strcmp(s, "<<=") == 0
+                    || strcmp(s, ">>=") == 0
+                    || strcmp(s, "**=") == 0);
+             if (!res)
+                 err_string("illegal augmmented assignment operator");
+         }
+     }
+     else {
+         for (j = 1; res && (j < nch); j += 2)
+             res = (validate_equal(CHILD(tree, j))
+                    && validate_testlist(CHILD(tree, j + 1)));
+     }
      return (res);
  }
***************
*** 2823,2829 ****
  
  
  DL_EXPORT(void)
  initparser(void)
!  {
      PyObject* module;
      PyObject* dict;
--- 2847,2855 ----
  
  
+ DL_IMPORT(void) initparser(void);
+ 
  DL_EXPORT(void)
  initparser(void)
! {
      PyObject* module;
      PyObject* dict;
***************
*** 2835,2840 ****
      if (parser_error == 0)
          parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
-     else
-         puts("parser module initialized more than once!");
  
      if ((parser_error == 0)
--- 2861,2864 ----