mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Patch 1144 by David Binger, fix for parser module. With unittest.
(I also cleared out all trailing whitespace in the C file.)
This commit is contained in:
parent
a1e9ec4e55
commit
fc158e25d6
2 changed files with 13 additions and 12 deletions
|
@ -136,6 +136,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_class_defs(self):
|
def test_class_defs(self):
|
||||||
self.check_suite("class foo():pass")
|
self.check_suite("class foo():pass")
|
||||||
|
self.check_suite("class foo(object):pass")
|
||||||
|
|
||||||
def test_import_from_statement(self):
|
def test_import_from_statement(self):
|
||||||
self.check_suite("from sys.path import *")
|
self.check_suite("from sys.path import *")
|
||||||
|
|
|
@ -861,7 +861,7 @@ VALIDATER(node); VALIDATER(small_stmt);
|
||||||
VALIDATER(class); VALIDATER(node);
|
VALIDATER(class); VALIDATER(node);
|
||||||
VALIDATER(parameters); VALIDATER(suite);
|
VALIDATER(parameters); VALIDATER(suite);
|
||||||
VALIDATER(testlist); VALIDATER(varargslist);
|
VALIDATER(testlist); VALIDATER(varargslist);
|
||||||
VALIDATER(vfpdef);
|
VALIDATER(vfpdef);
|
||||||
VALIDATER(stmt); VALIDATER(simple_stmt);
|
VALIDATER(stmt); VALIDATER(simple_stmt);
|
||||||
VALIDATER(expr_stmt); VALIDATER(power);
|
VALIDATER(expr_stmt); VALIDATER(power);
|
||||||
VALIDATER(del_stmt);
|
VALIDATER(del_stmt);
|
||||||
|
@ -874,7 +874,7 @@ VALIDATER(while); VALIDATER(for);
|
||||||
VALIDATER(try); VALIDATER(except_clause);
|
VALIDATER(try); VALIDATER(except_clause);
|
||||||
VALIDATER(test); VALIDATER(and_test);
|
VALIDATER(test); VALIDATER(and_test);
|
||||||
VALIDATER(not_test); VALIDATER(comparison);
|
VALIDATER(not_test); VALIDATER(comparison);
|
||||||
VALIDATER(comp_op);
|
VALIDATER(comp_op);
|
||||||
VALIDATER(star_expr); VALIDATER(expr);
|
VALIDATER(star_expr); VALIDATER(expr);
|
||||||
VALIDATER(xor_expr); VALIDATER(and_expr);
|
VALIDATER(xor_expr); VALIDATER(and_expr);
|
||||||
VALIDATER(shift_expr); VALIDATER(arith_expr);
|
VALIDATER(shift_expr); VALIDATER(arith_expr);
|
||||||
|
@ -988,11 +988,11 @@ validate_class(node *tree)
|
||||||
else {
|
else {
|
||||||
(void) validate_numnodes(tree, 4, "class");
|
(void) validate_numnodes(tree, 4, "class");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
if (nch == 7) {
|
if (nch == 7) {
|
||||||
res = ((validate_lparen(CHILD(tree, 2)) &&
|
res = ((validate_lparen(CHILD(tree, 2)) &&
|
||||||
validate_testlist(CHILD(tree, 3)) &&
|
validate_arglist(CHILD(tree, 3)) &&
|
||||||
validate_rparen(CHILD(tree, 4))));
|
validate_rparen(CHILD(tree, 4))));
|
||||||
}
|
}
|
||||||
else if (nch == 6) {
|
else if (nch == 6) {
|
||||||
|
@ -1177,11 +1177,11 @@ validate_varargslist_trailer(node *tree, int start)
|
||||||
}
|
}
|
||||||
while (res && i+1 < nch) { /* validate (',' vfpdef ['=' test])* */
|
while (res && i+1 < nch) { /* validate (',' vfpdef ['=' test])* */
|
||||||
res = validate_comma(CHILD(tree, i));
|
res = validate_comma(CHILD(tree, i));
|
||||||
if (TYPE(CHILD(tree, i+1)) == DOUBLESTAR)
|
if (TYPE(CHILD(tree, i+1)) == DOUBLESTAR)
|
||||||
break;
|
break;
|
||||||
res = res && validate_vfpdef(CHILD(tree, i+1));
|
res = res && validate_vfpdef(CHILD(tree, i+1));
|
||||||
if (res && i+2 < nch && TYPE(CHILD(tree, i+2)) == EQUAL) {
|
if (res && i+2 < nch && TYPE(CHILD(tree, i+2)) == EQUAL) {
|
||||||
res = res && (i+3 < nch)
|
res = res && (i+3 < nch)
|
||||||
&& validate_test(CHILD(tree, i+3));
|
&& validate_test(CHILD(tree, i+3));
|
||||||
i += 4;
|
i += 4;
|
||||||
}
|
}
|
||||||
|
@ -1234,7 +1234,7 @@ validate_varargslist(node *tree)
|
||||||
int sym;
|
int sym;
|
||||||
node *ch;
|
node *ch;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
return 0;
|
return 0;
|
||||||
if (nch < 1) {
|
if (nch < 1) {
|
||||||
|
@ -1242,7 +1242,7 @@ validate_varargslist(node *tree)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
while (i < nch) {
|
while (i < nch) {
|
||||||
ch = CHILD(tree, i);
|
ch = CHILD(tree, i);
|
||||||
sym = TYPE(ch);
|
sym = TYPE(ch);
|
||||||
if (sym == vfpdef || sym == tfpdef) {
|
if (sym == vfpdef || sym == tfpdef) {
|
||||||
/* validate (vfpdef ['=' test] ',')+ */
|
/* validate (vfpdef ['=' test] ',')+ */
|
||||||
|
@ -1443,7 +1443,7 @@ validate_compound_stmt(node *tree)
|
||||||
static int
|
static int
|
||||||
validate_yield_or_testlist(node *tree)
|
validate_yield_or_testlist(node *tree)
|
||||||
{
|
{
|
||||||
if (TYPE(tree) == yield_expr)
|
if (TYPE(tree) == yield_expr)
|
||||||
return validate_yield_expr(tree);
|
return validate_yield_expr(tree);
|
||||||
else
|
else
|
||||||
return validate_testlist(tree);
|
return validate_testlist(tree);
|
||||||
|
@ -1675,7 +1675,7 @@ validate_import_name(node *tree)
|
||||||
&& validate_dotted_as_names(CHILD(tree, 1)));
|
&& validate_dotted_as_names(CHILD(tree, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function to count the number of leading dots in
|
/* Helper function to count the number of leading dots in
|
||||||
* 'from ...module import name'
|
* 'from ...module import name'
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
|
@ -2361,7 +2361,7 @@ validate_decorator(node *tree)
|
||||||
static int
|
static int
|
||||||
validate_decorators(node *tree)
|
validate_decorators(node *tree)
|
||||||
{
|
{
|
||||||
int i, nch, ok;
|
int i, nch, ok;
|
||||||
nch = NCH(tree);
|
nch = NCH(tree);
|
||||||
ok = validate_ntype(tree, decorators) && nch >= 1;
|
ok = validate_ntype(tree, decorators) && nch >= 1;
|
||||||
|
|
||||||
|
@ -2372,7 +2372,7 @@ validate_decorators(node *tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* funcdef:
|
/* funcdef:
|
||||||
*
|
*
|
||||||
* -5 -4 -3 -2 -1
|
* -5 -4 -3 -2 -1
|
||||||
* 'def' NAME parameters ':' suite
|
* 'def' NAME parameters ':' suite
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue