summaryrefslogtreecommitdiffstats
path: root/Modules/parsermodule.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-12-07 15:15:22 (GMT)
committerGeorg Brandl <georg@python.org>2008-12-07 15:15:22 (GMT)
commiteee3116690e8c587fdf06af65427efabf4390554 (patch)
treed301c8e3f83ed604ba9fe85c29e0568964c415da /Modules/parsermodule.c
parent6485f247e44509536a0dfe173c47957cbadf04e1 (diff)
downloadcpython-eee3116690e8c587fdf06af65427efabf4390554.zip
cpython-eee3116690e8c587fdf06af65427efabf4390554.tar.gz
cpython-eee3116690e8c587fdf06af65427efabf4390554.tar.bz2
Merged revisions 67463,67572,67576,67628 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67463 | skip.montanaro | 2008-12-01 02:55:22 +0100 (Mon, 01 Dec 2008) | 1 line typo in comment ........ r67572 | georg.brandl | 2008-12-05 10:23:14 +0100 (Fri, 05 Dec 2008) | 2 lines #4458: recognize "-" as an argument, not a malformed option in gnu_getopt(). ........ r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines #4529: fix parser's validation for try-except-finally statements. ........ r67628 | skip.montanaro | 2008-12-07 03:16:00 +0100 (Sun, 07 Dec 2008) | 1 line muffed the default case ........
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r--Modules/parsermodule.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 51660aa..6778fb4 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1862,6 +1862,7 @@ validate_for(node *tree)
/* try_stmt:
* 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
+ ['finally' ':' suite]
* | 'try' ':' suite 'finally' ':' suite
*
*/
@@ -1887,35 +1888,34 @@ validate_try(node *tree)
PyErr_Format(parser_error,
"Illegal number of children for try/%s node.", name);
}
- /* Skip past except_clause sections: */
+ /* Handle try/finally statement */
+ if (res && (TYPE(CHILD(tree, pos)) == NAME) &&
+ (strcmp(STR(CHILD(tree, pos)), "finally") == 0)) {
+ res = (validate_numnodes(tree, 6, "try/finally")
+ && validate_colon(CHILD(tree, 4))
+ && validate_suite(CHILD(tree, 5)));
+ return (res);
+ }
+ /* try/except statement: skip past except_clause sections */
while (res && (TYPE(CHILD(tree, pos)) == except_clause)) {
res = (validate_except_clause(CHILD(tree, pos))
&& validate_colon(CHILD(tree, pos + 1))
&& validate_suite(CHILD(tree, pos + 2)));
pos += 3;
}
- if (res && (pos < nch)) {
- res = validate_ntype(CHILD(tree, pos), NAME);
- if (res && (strcmp(STR(CHILD(tree, pos)), "finally") == 0))
- res = (validate_numnodes(tree, 6, "try/finally")
- && validate_colon(CHILD(tree, 4))
- && validate_suite(CHILD(tree, 5)));
- else if (res) {
- if (nch == (pos + 3)) {
- res = ((strcmp(STR(CHILD(tree, pos)), "except") == 0)
- || (strcmp(STR(CHILD(tree, pos)), "else") == 0));
- if (!res)
- err_string("illegal trailing triple in try statement");
- }
- else if (nch == (pos + 6)) {
- res = (validate_name(CHILD(tree, pos), "except")
- && validate_colon(CHILD(tree, pos + 1))
- && validate_suite(CHILD(tree, pos + 2))
- && validate_name(CHILD(tree, pos + 3), "else"));
- }
- else
- res = validate_numnodes(tree, pos + 3, "try/except");
- }
+ /* skip else clause */
+ if (res && (TYPE(CHILD(tree, pos)) == NAME) &&
+ (strcmp(STR(CHILD(tree, pos)), "else") == 0)) {
+ res = (validate_colon(CHILD(tree, pos + 1))
+ && validate_suite(CHILD(tree, pos + 2)));
+ pos += 3;
+ }
+ if (res && pos < nch) {
+ /* last clause must be a finally */
+ res = (validate_name(CHILD(tree, pos), "finally")
+ && validate_numnodes(tree, pos + 3, "try/except/finally")
+ && validate_colon(CHILD(tree, pos + 1))
+ && validate_suite(CHILD(tree, pos + 2)));
}
return (res);
}