From: <fwi...@us...> - 2008-08-27 00:44:38
|
Revision: 5254 http://jython.svn.sourceforge.net/jython/?rev=5254&view=rev Author: fwierzbicki Date: 2008-08-27 00:44:35 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Fix illegal Lambda statements and more illegal assigns. Also raise exceptions on illegal gen expression arguments. 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 20:17:50 UTC (rev 5253) +++ branches/nowalker/grammar/Python.g 2008-08-27 00:44:35 UTC (rev 5254) @@ -851,7 +851,7 @@ //with_var: ('as' | NAME) expr with_var returns [exprType etype] - : (AS | NAME) expr[expr_contextType.Load] + : (AS | NAME) expr[expr_contextType.Store] { $etype = (exprType)$expr.tree; } @@ -1397,14 +1397,18 @@ @init { List arguments = new ArrayList(); List kws = new ArrayList(); + List gens = new ArrayList(); } - : argument[arguments, kws] (COMMA argument[arguments, kws])* + : argument[arguments, kws, gens, true] (COMMA argument[arguments, kws, gens, false])* (COMMA ( STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? | DOUBLESTAR k=test[expr_contextType.Load] )? )? { + if (arguments.size() > 1 && gens.size() > 0) { + actions.errorGenExpNotSoleArg(new PythonTree($arglist.start)); + } $args=arguments; $keywords=kws; $starargs=(exprType)$s.tree; @@ -1422,19 +1426,20 @@ ; //argument: test [gen_for] | test '=' test # Really [keyword '='] test -argument[List arguments, List kws] -@init { - List gens = new ArrayList(); -} +argument[List arguments, List kws, List gens, boolean first] returns [boolean genarg] : t1=test[expr_contextType.Load] ((ASSIGN t2=test[expr_contextType.Load]) { $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); } - | gen_for[gens] + | gen_for[$gens] { - Collections.reverse(gens); - comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + if (!first) { + actions.errorGenExpNotSoleArg($gen_for.tree); + } + $genarg = true; + Collections.reverse($gens); + comprehensionType[] c = (comprehensionType[])$gens.toArray(new comprehensionType[$gens.size()]); arguments.add(new GeneratorExp($gen_for.start, (exprType)$t1.tree, c)); } | { Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 20:17:50 UTC (rev 5253) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-27 00:44:35 UTC (rev 5254) @@ -299,6 +299,9 @@ if (tree instanceof GeneratorExp) { GeneratorExp g = (GeneratorExp)tree; recurseSetContext(g.elt, context); + } else if (tree instanceof ListComp) { + ListComp lc = (ListComp)tree; + recurseSetContext(lc.elt, context); } else if (!(tree instanceof ListComp)) { for (int i=0; i<tree.getChildCount(); i++) { recurseSetContext(tree.getChild(i), context); @@ -617,6 +620,8 @@ 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 Lambda) { + errorHandler.error("can't assign to lambda", 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. |