summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-02-27 00:24:13 (GMT)
committerThomas Wouters <thomas@python.org>2006-02-27 00:24:13 (GMT)
commitdca3b9c797f6dd4b08d590fa2aa1031e22ab598e (patch)
treed2b7aa53793110100965906b1266296d08bd4ec1 /Grammar
parentd3a5f53a27be821cfdff869fd8ad93a060497e8c (diff)
downloadcpython-dca3b9c797f6dd4b08d590fa2aa1031e22ab598e.zip
cpython-dca3b9c797f6dd4b08d590fa2aa1031e22ab598e.tar.gz
cpython-dca3b9c797f6dd4b08d590fa2aa1031e22ab598e.tar.bz2
PEP 308 implementation, including minor refdocs and some testcases. It
breaks the parser module, because it adds the if/else construct as well as two new grammar rules for backward compatibility. If no one else fixes parsermodule, I guess I'll go ahead and fix it later this week. The TeX code was checked with texcheck.py, but not rendered. There is actually a slight incompatibility: >>> (x for x in lambda:0) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: iteration over non-sequence changes into >>> (x for x in lambda: 0) File "<stdin>", line 1 (x for x in lambda: 0) ^ SyntaxError: invalid syntax Since there's no way the former version can be useful, it's probably a bugfix ;)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/Grammar15
1 files changed, 12 insertions, 3 deletions
diff --git a/Grammar/Grammar b/Grammar/Grammar
index 666ff44..b11f33e 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -83,7 +83,17 @@ try_stmt: ('try' ':' suite
except_clause: 'except' [test [',' test]]
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
-test: and_test ('or' and_test)* | lambdef
+# Backward compatibility cruft to support:
+# [ x for x in lambda: True, lambda: False if x() ]
+# even while also allowing:
+# lambda x: 5 if x else 2
+# (But not a mix of the two)
+testlist_safe: old_test [(',' old_test)+ [',']]
+old_test: or_test | old_lambdef
+old_lambdef: 'lambda' [varargslist] ':' old_test
+
+test: or_test ['if' or_test 'else' test] | lambdef
+or_test: and_test ('or' and_test)*
and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)*
@@ -110,7 +120,6 @@ subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
sliceop: ':' [test]
exprlist: expr (',' expr)* [',']
testlist: test (',' test)* [',']
-testlist_safe: test [(',' test)+ [',']]
dictmaker: test ':' test (',' test ':' test)* [',']
classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
@@ -123,7 +132,7 @@ list_for: 'for' exprlist 'in' testlist_safe [list_iter]
list_if: 'if' test [list_iter]
gen_iter: gen_for | gen_if
-gen_for: 'for' exprlist 'in' test [gen_iter]
+gen_for: 'for' exprlist 'in' or_test [gen_iter]
gen_if: 'if' test [gen_iter]
testlist1: test (',' test)*