From: <fwi...@us...> - 2008-08-21 02:58:26
|
Revision: 5228 http://jython.svn.sourceforge.net/jython/?rev=5228&view=rev Author: fwierzbicki Date: 2008-08-21 02:58:24 +0000 (Thu, 21 Aug 2008) Log Message: ----------- debugging of some expr_contextType values. 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-20 23:01:42 UTC (rev 5227) +++ branches/nowalker/grammar/Python.g 2008-08-21 02:58:24 UTC (rev 5228) @@ -411,7 +411,7 @@ //fpdef: NAME | '(' fplist ')' fpdef[expr_contextType ctype] : NAME -> ^(PYNODE<Name>[$NAME, $NAME.text, ctype]) - | (LPAREN fpdef[expr_contextType.Load] COMMA) => LPAREN fplist RPAREN + | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN -> fplist | LPAREN fplist RPAREN -> ^(LPAREN<Tuple>[$fplist.start, actions.makeExprs($fplist.etypes), expr_contextType.Store]) @@ -458,11 +458,11 @@ } : - ((testlist[expr_contextType.Load] augassign) => lhs=testlist[expr_contextType.AugStore] + ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] ( (aay=augassign y1=yield_expr {stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aay.op, (exprType)$y1.tree);}) | (aat=augassign rhs=testlist[expr_contextType.Load] {stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aat.op, (exprType)$rhs.tree);}) ) - |(testlist[expr_contextType.Load] ASSIGN) => lhs=testlist[expr_contextType.Store] + |(testlist[null] ASSIGN) => lhs=testlist[expr_contextType.Store] ( | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ -> ^(PYNODE<Assign>[$at, actions.makeAssignTargets((exprType)$lhs.tree, $t), actions.makeAssignValue($t)])) | ((ay=ASSIGN y2+=yield_expr)+ -> ^(PYNODE<Assign>[$ay, actions.makeAssignTargets((exprType)$lhs.tree, $y2), actions.makeAssignValue($y2)])) @@ -502,7 +502,7 @@ //not in CPython's Grammar file printlist returns [boolean newline, List elts] - : (test[expr_contextType.Load] COMMA) => + : (test[null] COMMA) => t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* (trailcomma=COMMA)? { $elts=$t; if ($trailcomma == null) { @@ -520,7 +520,7 @@ //XXX: would be nice if printlist and printlist2 could be merged. //not in CPython's Grammar file printlist2 returns [boolean newline, List elts] - : (test[expr_contextType.Load] COMMA test[expr_contextType.Load]) => + : (test[null] COMMA test[null]) => t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* (trailcomma=COMMA)? { $elts=$t; if ($trailcomma == null) { @@ -767,7 +767,7 @@ //test: or_test ['if' or_test 'else' test] | lambdef test[expr_contextType ctype] :o1=or_test[ctype] - ( (IF or_test[expr_contextType.Load] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] + ( (IF or_test[null] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] -> ^(IF<IfExp>[$IF, (exprType)$o2.tree, (exprType)$o1.tree, (exprType)$e.tree]) | -> or_test ) @@ -1034,14 +1034,18 @@ $testlist_gexp.tree = etype; } } - : t+=test[expr_contextType.Load] - ( ((options {k=2;}: c1=COMMA t+=test[expr_contextType.Load])* (c2=COMMA)? + : t+=test[$expr::ctype] + ( ((options {k=2;}: c1=COMMA t+=test[$expr::ctype])* (c2=COMMA)? -> { $c1 != null || $c2 != null }? ^(PYNODE<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) -> test ) | ( gen_for[gens] { Collections.reverse(gens); comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + exprType e = (exprType)$t.get(0); + if (e instanceof Context) { + ((Context)e).setContext(expr_contextType.Load); + } etype = new GeneratorExp($gen_for.start, (exprType)$t.get(0), c); } ) @@ -1107,7 +1111,7 @@ } } : d1=DOT DOT DOT -> DOT<Ellipsis>[$d1] - | (test[expr_contextType.Load] COLON) => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? { + | (test[null] COLON) => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? { $sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree); } | (COLON) => c2=COLON (upper2=test[expr_contextType.Load])? (sliceop)? { @@ -1122,8 +1126,8 @@ //exprlist: expr (',' expr)* [','] exprlist[expr_contextType ctype] returns [exprType etype] - : (expr[expr_contextType.Load] COMMA) => e+=expr[ctype] (options {k=2;}: COMMA e+=expr[ctype])* (COMMA)? { - $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); + : (expr[null] COMMA) => e+=expr[ctype] (options {k=2;}: COMMA e+=expr[ctype])* (COMMA)? { + $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); } | expr[ctype] { $etype = (exprType)$expr.tree; @@ -1145,7 +1149,7 @@ @after { $testlist.tree = etype; } - : (test[expr_contextType.Load] COMMA) => t+=test[ctype] (options {k=2;}: c1=COMMA t+=test[ctype])* (c2=COMMA)? { + : (test[null] COMMA) => t+=test[ctype] (options {k=2;}: c1=COMMA t+=test[ctype])* (c2=COMMA)? { etype = new Tuple($testlist.start, actions.makeExprs($t), ctype); } | test[ctype] { @@ -1214,7 +1218,11 @@ ( (ASSIGN t2=test[expr_contextType.Load]) { $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); } - | gen_for[gens] //FIXME + | gen_for[gens] { + Collections.reverse(gens); + comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + arguments.add(new GeneratorExp($gen_for.start, (exprType)$t1.tree, c)); + } | {$arguments.add($t1.tree);} ) ; Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-20 23:01:42 UTC (rev 5227) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-21 02:58:24 UTC (rev 5228) @@ -293,12 +293,21 @@ exprType makeAssignValue(List rhs) { exprType value = (exprType)rhs.get(rhs.size() -1); + maybeSetContext(value, expr_contextType.Load); + if (value instanceof Tuple) { + exprType[] elts = ((Tuple)value).elts; + for (int i=0;i<elts.length;i++) { + maybeSetContext(elts[i], expr_contextType.Load); + } + } + return value; + } - if (value instanceof Context) { + void maybeSetContext(PythonTree tree, expr_contextType context) { + if (tree instanceof Context) { //XXX: for Tuples, etc -- will need to recursively set to expr_contextType.Load. - ((Context)value).setContext(expr_contextType.Load); + ((Context)tree).setContext(context); } - return value; } argumentsType makeArgumentsType(Token t, List params, Token snameToken, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |