summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-08-25 22:42:40 (GMT)
committerFred Drake <fdrake@acm.org>2000-08-25 22:42:40 (GMT)
commit28f739aad47f1022fda19e4f3d8ad1b8228d221b (patch)
tree218914b8a2a04262fe756cc6ddfc3ffd7b37c753 /Modules
parent6ef68b5b01c7898624b8baa5d042522d3d6532af (diff)
downloadcpython-28f739aad47f1022fda19e4f3d8ad1b8228d221b.zip
cpython-28f739aad47f1022fda19e4f3d8ad1b8228d221b.tar.gz
cpython-28f739aad47f1022fda19e4f3d8ad1b8228d221b.tar.bz2
Update the parser module to support augmented assignment.
Add some test cases.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/parsermodule.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index ef8ec9b..50161cf 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1467,10 +1467,34 @@ validate_expr_stmt(node *tree)
&& is_odd(nch)
&& 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)));
+ 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);
}
@@ -2822,9 +2846,11 @@ static PyMethodDef parser_functions[] = {
};
+DL_IMPORT(void) initparser(void);
+
DL_EXPORT(void)
initparser(void)
- {
+{
PyObject* module;
PyObject* dict;
@@ -2834,8 +2860,6 @@ initparser(void)
if (parser_error == 0)
parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
- else
- puts("parser module initialized more than once!");
if ((parser_error == 0)
|| (PyDict_SetItemString(dict, "ParserError", parser_error) != 0)) {