From 00afa480e12bd1b6aecdcae407a131d5309cd7da Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Fri, 25 Aug 2000 22:42:40 +0000 Subject: Update the parser module to support augmented assignment. Add some test cases. --- Modules/parsermodule.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'Modules/parsermodule.c') diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index ef8ec9bcf6..50161cffed 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)) { -- cgit v1.2.1