From: <fwi...@us...> - 2008-08-26 20:17:53
|
Revision: 5253 http://jython.svn.sourceforge.net/jython/?rev=5253&view=rev Author: fwierzbicki Date: 2008-08-26 20:17:50 +0000 (Tue, 26 Aug 2008) Log Message: ----------- checking for bad assignment statements. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-26 19:37:34 UTC (rev 5252) +++ branches/nowalker/grammar/Python.g 2008-08-26 20:17:50 UTC (rev 5253) @@ -433,6 +433,9 @@ //fpdef: NAME | '(' fplist ')' fpdef[expr_contextType ctype] +@after { + actions.checkAssign((exprType)$fpdef.tree); +} : NAME -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN @@ -498,11 +501,13 @@ : ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] ( (aay=augassign y1=yield_expr { + actions.checkAssign((exprType)$lhs.tree); stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aay.op, (exprType)$y1.tree); } ) | (aat=augassign rhs=testlist[expr_contextType.Load] { + actions.checkAssign((exprType)$lhs.tree); stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aat.op, (exprType)$rhs.tree); } ) Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 19:37:34 UTC (rev 5252) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 20:17:50 UTC (rev 5253) @@ -276,16 +276,12 @@ exprType[] makeAssignTargets(exprType lhs, List rhs) { exprType[] e = new exprType[rhs.size()]; + checkAssign(lhs); e[0] = lhs; for(int i=0;i<rhs.size() - 1;i++) { - Object o = rhs.get(i); - if (o instanceof PythonParser.testlist_return) { - //XXX: Check to see if this is really happening anymore - PythonParser.testlist_return r = (PythonParser.testlist_return)o; - e[i + 1] = (exprType)r.getTree(); - } else { - e[i + 1] = (exprType)o; - } + exprType r = (exprType)rhs.get(i); + checkAssign(r); + e[i + 1] = r; } return e; } @@ -339,6 +335,7 @@ if (args != null) { for(int i=0;i<args.size();i++) { exprType[] e = (exprType[])args.get(i); + checkAssign(e[0]); Name arg = (Name)e[0]; k.add(new keywordType(arg, arg.id, e[1])); } @@ -618,6 +615,8 @@ errorHandler.error("can't assign to number", e); } else if (e instanceof Yield) { errorHandler.error("can't assign to yield expression", e); + } else if (e instanceof BinOp) { + errorHandler.error("can't assign to operator", e); } else if (e instanceof Tuple) { //XXX: performance problem? Any way to do this better? exprType[] elts = ((Tuple)e).elts; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |