[Python-checkins] CVS: python/dist/src/Grammar Grammar,1.44,1.45

Guido van Rossum gvanrossum@users.sourceforge.net
2001年10月15日 08:44:06 -0700


Update of /cvsroot/python/python/dist/src/Grammar
In directory usw-pr-cvs1:/tmp/cvs-serv24320/Grammar
Modified Files:
	Grammar 
Log Message:
Very subtle syntax change: in a list comprehension, the testlist in
"for <var> in <testlist> may no longer be a single test followed by
a comma. This solves SF bug #431886. Note that if the testlist
contains more than one test, a trailing comma is still allowed, for
maximum backward compatibility; but this example is not:
 [(x, y) for x in range(10), for y in range(10)]
 ^
The fix involved creating a new nonterminal 'testlist_safe' whose
definition doesn't allow the trailing comma if there's only one test:
 testlist_safe: test [(',' test)+ [',']]
Index: Grammar
===================================================================
RCS file: /cvsroot/python/python/dist/src/Grammar/Grammar,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** Grammar	2001年08月08日 05:00:17	1.44
--- Grammar	2001年10月15日 15:44:04	1.45
***************
*** 90,93 ****
--- 90,94 ----
 exprlist: expr (',' expr)* [',']
 testlist: test (',' test)* [',']
+ testlist_safe: test [(',' test)+ [',']]
 dictmaker: test ':' test (',' test ':' test)* [',']
 
***************
*** 98,101 ****
 
 list_iter: list_for | list_if
! list_for: 'for' exprlist 'in' testlist [list_iter]
 list_if: 'if' test [list_iter]
--- 99,102 ----
 
 list_iter: list_for | list_if
! list_for: 'for' exprlist 'in' testlist_safe [list_iter]
 list_if: 'if' test [list_iter]

AltStyle によって変換されたページ (->オリジナル) /