From: <fwi...@us...> - 2008-01-12 16:08:23
|
Revision: 4016 http://jython.svn.sourceforge.net/jython/?rev=4016&view=rev Author: fwierzbicki Date: 2008-01-12 08:08:14 -0800 (Sat, 12 Jan 2008) Log Message: ----------- Properly handle nested AND with parens. Still need to work through the other BoolOps. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-11 12:09:20 UTC (rev 4015) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-12 16:08:14 UTC (rev 4016) @@ -178,6 +178,7 @@ ListFor; ListIf; FinalBody; + Parens; } @header { @@ -666,7 +667,7 @@ // NAME | NUMBER | STRING+) atom : LPAREN ( yield_expr -> ^(Tuple ^(Elts yield_expr)) - | testlist_gexp {debug("parsed testlist_gexp");} -> testlist_gexp + | testlist_gexp {debug("parsed testlist_gexp");} -> ^(Parens testlist_gexp) | -> ^(Tuple) ) RPAREN Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-11 12:09:20 UTC (rev 4015) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-12 16:08:14 UTC (rev 4016) @@ -881,18 +881,18 @@ ; //FIXME: lots of placeholders -test[expr_contextType ctype] returns [exprType etype] +test[expr_contextType ctype] returns [exprType etype, boolean parens] : ^(AND left=test[ctype] right=test[ctype]) { List values = new ArrayList(); boolean leftIsAnd = false; boolean rightIsAnd = false; BoolOp leftB = null; BoolOp rightB = null; - if ($left.start.getType() == AND) { + if (! $left.parens && $left.start.getType() == AND) { leftIsAnd = true; leftB = (BoolOp)$left.etype; } - if ($right.start.getType() == AND) { + if (! $right.parens && $right.start.getType() == AND) { rightIsAnd = true; rightB = (BoolOp)$right.etype; } @@ -986,8 +986,9 @@ comparators[0] = $targs.etype; val = $left.etype; } + $parens = $left.parens; $etype = new Compare($comp_op.start, val, ops, comparators); - debug("COMP_OP: " + $comp_op.start); + debug("COMP_OP: " + $comp_op.start + ":::" + $etype + ":::" + $parens); } | atom[ctype] { debug("matched atom"); @@ -1007,7 +1008,7 @@ | ^(IfExp ^(Test t1=test[ctype]) ^(Body t2=test[ctype]) ^(OrElse t3=test[ctype])) { $etype = new IfExp($IfExp, $t1.etype, $t2.etype, $t3.etype); } - ; +; comp_op returns [cmpopType op] : LESS {$op = cmpopType.Lt;} @@ -1045,7 +1046,7 @@ ; //FIXME: lots of placeholders -atom[expr_contextType ctype] returns [exprType etype] +atom[expr_contextType ctype] returns [exprType etype, boolean parens] : ^(Tuple (^(Elts elts[ctype]))?) { debug("matched Tuple"); exprType[] e; @@ -1154,6 +1155,11 @@ | ^(NOT test[ctype]) { $etype = new UnaryOp($NOT, unaryopType.Not, $test.etype); } + | ^(Parens test[ctype]) { + debug("PARENS! " + $test.etype); + $etype = $test.etype; + $parens = true; + } ; comprehension[expr_contextType ctype] returns [exprType etype] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |