[Jython-checkins] jython: Fix test_augassign.
frank.wierzbicki
jython-checkins at python.org
Thu Apr 19 20:05:00 CEST 2012
http://hg.python.org/jython/rev/beeaa4ff41e8
changeset: 6611:beeaa4ff41e8
user: Frank Wierzbicki <fwierzbicki at gmail.com>
date: Thu Apr 19 11:04:53 2012 -0700
summary:
Fix test_augassign.
files:
grammar/Python.g | 4 +-
src/org/python/antlr/GrammarActions.java | 18 ++++++++++-
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/grammar/Python.g b/grammar/Python.g
--- a/grammar/Python.g
+++ b/grammar/Python.g
@@ -643,13 +643,13 @@
: ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore]
( (aay=augassign y1=yield_expr
{
- actions.checkAssign(actions.castExpr($lhs.tree));
+ actions.checkAugAssign(actions.castExpr($lhs.tree));
stype = new AugAssign($lhs.tree, actions.castExpr($lhs.tree), $aay.op, actions.castExpr($y1.etype));
}
)
| (aat=augassign rhs=testlist[expr_contextType.Load]
{
- actions.checkAssign(actions.castExpr($lhs.tree));
+ actions.checkAugAssign(actions.castExpr($lhs.tree));
stype = new AugAssign($lhs.tree, actions.castExpr($lhs.tree), $aat.op, actions.castExpr($rhs.tree));
}
)
diff --git a/src/org/python/antlr/GrammarActions.java b/src/org/python/antlr/GrammarActions.java
--- a/src/org/python/antlr/GrammarActions.java
+++ b/src/org/python/antlr/GrammarActions.java
@@ -606,7 +606,7 @@
}
}
- void checkAssign(expr e) {
+ private void checkGenericAssign(expr e) {
if (e instanceof Name && ((Name)e).getInternalId().equals("None")) {
errorHandler.error("assignment to None", e);
} else if (e instanceof GeneratorExp) {
@@ -631,7 +631,21 @@
errorHandler.error("can't assign to conditional expression", e);
} else if (e instanceof ListComp) {
errorHandler.error("can't assign to list comprehension", e);
- } else if (e instanceof Tuple) {
+ }
+ }
+
+ void checkAugAssign(expr e) {
+ checkGenericAssign(e);
+ if (e instanceof Tuple) {
+ errorHandler.error("assignment to tuple illegal for augmented assignment", e);
+ } else if (e instanceof org.python.antlr.ast.List) {
+ errorHandler.error("assignment to list illegal for augmented assignment", e);
+ }
+ }
+
+ void checkAssign(expr e) {
+ checkGenericAssign(e);
+ if (e instanceof Tuple) {
//XXX: performance problem? Any way to do this better?
List<expr> elts = ((Tuple)e).getInternalElts();
if (elts.size() == 0) {
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list