summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 (GMT)
commit4905e80c3d2f6abb613d212f0313d1dfe09475dc (patch)
treedf849b7313a57c1d844567bcd45b32f7e89ac0ca /Grammar
parent10430ad7aace46c93939341817b97df48951d5a2 (diff)
downloadcpython-4905e80c3d2f6abb613d212f0313d1dfe09475dc.zip
cpython-4905e80c3d2f6abb613d212f0313d1dfe09475dc.tar.gz
cpython-4905e80c3d2f6abb613d212f0313d1dfe09475dc.tar.bz2
fix an ambiguity in the grammar from the implementation of extended unpacking
(one which was strangely "resolved" by pgen) This also kills the unused testlist1 rule and fixes parse tree validation of extended unpacking.
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/Grammar15
1 files changed, 7 insertions, 8 deletions
diff --git a/Grammar/Grammar b/Grammar/Grammar
index 1f226b8..19f67de 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -37,8 +37,9 @@ stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
-expr_stmt: testlist (augassign (yield_expr|testlist) |
- ('=' (yield_expr|testlist))*)
+expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
+ ('=' (yield_expr|testlist_star_expr))*)
+testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
# For normal assignments, additional restrictions enforced by the interpreter
@@ -86,9 +87,9 @@ lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
or_test: and_test ('or' and_test)*
and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison
-comparison: star_expr (comp_op star_expr)*
+comparison: expr (comp_op expr)*
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
-star_expr: ['*'] expr
+star_expr: '*' expr
expr: xor_expr ('|' xor_expr)*
xor_expr: and_expr ('^' and_expr)*
and_expr: shift_expr ('&' shift_expr)*
@@ -101,12 +102,12 @@ atom: ('(' [yield_expr|testlist_comp] ')' |
'[' [testlist_comp] ']' |
'{' [dictorsetmaker] '}' |
NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
-testlist_comp: test ( comp_for | (',' test)* [','] )
+testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: subscript (',' subscript)* [',']
subscript: test | [test] ':' [test] [sliceop]
sliceop: ':' [test]
-exprlist: star_expr (',' star_expr)* [',']
+exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
testlist: test (',' test)* [',']
dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
(test (comp_for | (',' test)* [','])) )
@@ -123,8 +124,6 @@ comp_iter: comp_for | comp_if
comp_for: 'for' exprlist 'in' or_test [comp_iter]
comp_if: 'if' test_nocond [comp_iter]
-testlist1: test (',' test)*
-
# not used in grammar, but may appear in "node" passed from Parser to Compiler
encoding_decl: NAME