summaryrefslogtreecommitdiff
path: root/Grammar
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 +0000
committerBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 +0000
commit8ccabc0faaf6b0af4ba2483c6212f324815fbef1 (patch)
tree966e4a08517baad4e4ffe16131d552883c74b45f /Grammar
parent01de313c26c12b4b1b965d495deef88ef4cf1995 (diff)
downloadcpython-8ccabc0faaf6b0af4ba2483c6212f324815fbef1.tar.gz
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 1f226b80b1..19f67dee5e 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