From: <fwi...@us...> - 2009-08-17 03:15:37
|
Revision: 6690 http://jython.svn.sourceforge.net/jython/?rev=6690&view=rev Author: fwierzbicki Date: 2009-08-17 03:15:31 +0000 (Mon, 17 Aug 2009) Log Message: ----------- Better match of CPython col_offset for factors with parens like: (a - b) * c Modified Paths: -------------- trunk/jython/Lib/test/test_ast.py trunk/jython/grammar/Python.g trunk/jython/src/org/python/antlr/GrammarActions.java Modified: trunk/jython/Lib/test/test_ast.py =================================================================== --- trunk/jython/Lib/test/test_ast.py 2009-08-17 02:30:53 UTC (rev 6689) +++ trunk/jython/Lib/test/test_ast.py 2009-08-17 03:15:31 UTC (rev 6690) @@ -67,11 +67,12 @@ # Parens and BoolOp "(a == '') and b", "not (a == '') or b", + # Parens and BinOp + "(a - b) * c", # for statements with naked tuples "for a,b in c: pass", "[(a,b) for a,b in c]", "((a,b) for a,b in c)", - ] # These are compiled through "single" @@ -336,6 +337,7 @@ ('Module', [('Continue', (1, 0))]), ('Module', [('Expr', (1, 0), ('BoolOp', (1, 0), ('And',), [('Compare', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('Eq',)], [('Str', (1, 6), '')]), ('Name', (1, 14), 'b', ('Load',))]))]), ('Module', [('Expr', (1, 0), ('BoolOp', (1, 0), ('Or',), [('UnaryOp', (1, 0), ('Not',), ('Compare', (1, 5), ('Name', (1, 5), 'a', ('Load',)), [('Eq',)], [('Str', (1, 10), '')])), ('Name', (1, 17), 'b', ('Load',))]))]), +('Module', [('Expr', (1, 0), ('BinOp', (1, 0), ('BinOp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), ('Sub',), ('Name', (1, 5), 'b', ('Load',))), ('Mult',), ('Name', (1, 10), 'c', ('Load',))))]), ('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)), ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load',)), [('Pass', (1, 14))], [])]), ('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-08-17 02:30:53 UTC (rev 6689) +++ trunk/jython/grammar/Python.g 2009-08-17 03:15:31 UTC (rev 6690) @@ -1204,7 +1204,7 @@ } @after { if (!ops.isEmpty()) { - $shift_expr.tree = actions.makeBinOp($left.tree, ops, $right, toks); + $shift_expr.tree = actions.makeBinOp($left.start, $left.tree, ops, $right, toks); } $lparen = $left.lparen; } @@ -1237,7 +1237,7 @@ } @after { if (!ops.isEmpty()) { - $arith_expr.tree = actions.makeBinOp($left.tree, ops, $right, toks); + $arith_expr.tree = actions.makeBinOp($left.start, $left.tree, ops, $right, toks); } $lparen = $left.lparen; } @@ -1279,7 +1279,11 @@ @after { $lparen = $left.lparen; if (!ops.isEmpty()) { - $term.tree = actions.makeBinOp($left.tree, ops, $right, toks); + Token tok = $left.start; + if ($left.lparen != null) { + tok = $left.lparen; + } + $term.tree = actions.makeBinOp(tok, $left.tree, ops, $right, toks); } } : left=factor Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2009-08-17 02:30:53 UTC (rev 6689) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2009-08-17 03:15:31 UTC (rev 6690) @@ -658,8 +658,8 @@ return current; } - BinOp makeBinOp(PythonTree left, List ops, List rights, List toks) { - BinOp current = new BinOp(left, castExpr(left), (operatorType)ops.get(0), castExpr(rights.get(0))); + BinOp makeBinOp(Token t, PythonTree left, List ops, List rights, List toks) { + BinOp current = new BinOp(t, castExpr(left), (operatorType)ops.get(0), castExpr(rights.get(0))); for (int i = 1; i< rights.size(); i++) { expr right = castExpr(rights.get(i)); operatorType op = (operatorType)ops.get(i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |