From: <fwi...@us...> - 2009-08-16 02:49:33
|
Revision: 6671 http://jython.svn.sourceforge.net/jython/?rev=6671&view=rev Author: fwierzbicki Date: 2009-08-16 02:49:27 +0000 (Sun, 16 Aug 2009) Log Message: ----------- Better match with CPython for col_offset on BoolOp with left arg in parens. Modified Paths: -------------- trunk/jython/grammar/Python.g trunk/jython/src/org/python/antlr/GrammarActions.java Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-08-16 02:36:35 UTC (rev 6670) +++ trunk/jython/grammar/Python.g 2009-08-16 02:49:27 UTC (rev 6671) @@ -1038,10 +1038,15 @@ ; //or_test: and_test ('or' and_test)* -or_test[expr_contextType ctype] +or_test + [expr_contextType ctype] returns [Token leftTok] @after { if ($or != null) { - $or_test.tree = actions.makeBoolOp($left.tree, boolopType.Or, $right); + Token tok = $left.start; + if ($left.leftTok != null) { + tok = $left.leftTok; + } + $or_test.tree = actions.makeBoolOp(tok, $left.tree, boolopType.Or, $right); } } : left=and_test[ctype] @@ -1053,10 +1058,15 @@ ; //and_test: not_test ('and' not_test)* -and_test[expr_contextType ctype] +and_test + [expr_contextType ctype] returns [Token leftTok] @after { if ($and != null) { - $and_test.tree = actions.makeBoolOp($left.tree, boolopType.And, $right); + Token tok = $left.start; + if ($left.leftTok != null) { + tok = $left.leftTok; + } + $and_test.tree = actions.makeBoolOp(tok, $left.tree, boolopType.And, $right); } } : left=not_test[ctype] @@ -1068,18 +1078,21 @@ ; //not_test: 'not' not_test | comparison -not_test[expr_contextType ctype] - : NOT nt=not_test[ctype] +not_test + [expr_contextType ctype] returns [Token leftTok] + : NOT nt=not_test[ctype] {$leftTok = $nt.leftTok;} -> ^(NOT<UnaryOp>[$NOT, unaryopType.Not, actions.castExpr($nt.tree)]) - | comparison[ctype] + | comparison[ctype] {$leftTok = $comparison.leftTok;} ; //comparison: expr (comp_op expr)* -comparison[expr_contextType ctype] +comparison + [expr_contextType ctype] returns [Token leftTok] @init { List cmps = new ArrayList(); } @after { + $leftTok = $left.leftTok; if (!cmps.isEmpty()) { $comparison.tree = new Compare($left.start, actions.castExpr($left.tree), actions.makeCmpOps(cmps), actions.castExprs($right)); @@ -1125,14 +1138,18 @@ //expr: xor_expr ('|' xor_expr)* -expr[expr_contextType ect] +expr + [expr_contextType ect] returns [Token leftTok] scope { expr_contextType ctype; + Token lparen; } @init { $expr::ctype = ect; + $expr::lparen = null; } @after { + $leftTok = $expr::lparen; if ($op != null) { $expr.tree = actions.makeBinOp($left.tree, operatorType.BitOr, $right); } @@ -1342,7 +1359,7 @@ // '`' testlist1 '`' | // NAME | NUMBER | STRING+) atom - : LPAREN + : LPAREN {$expr::lparen = $LPAREN;} ( yield_expr -> yield_expr | testlist_gexp Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2009-08-16 02:36:35 UTC (rev 6670) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2009-08-16 02:49:27 UTC (rev 6671) @@ -642,11 +642,11 @@ return result; } - BoolOp makeBoolOp(PythonTree left, boolopType op, List right) { + BoolOp makeBoolOp(Token t, PythonTree left, boolopType op, List right) { List values = new ArrayList(); values.add(left); values.addAll(right); - return new BoolOp(left, op, castExprs(values)); + return new BoolOp(t, op, castExprs(values)); } BinOp makeBinOp(PythonTree left, operatorType op, List rights) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |