Skip to content

Commit

Permalink
Adds better support for nested parenthesis. See issue #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Troy Melhase committed Feb 6, 2012
1 parent 873f67a commit ad5b3fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions java2python/compiler/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,19 @@ def acceptMethodCall(self, node, memo):
arg.left.walk(child, memo)
arg.right = arg = expr(parent=self)

skipParensParents = (
tokens.IF,
tokens.WHILE,
tokens.SWITCH,
tokens.SYNCHRONIZED,
)

def acceptParentesizedExpr(self, node, memo):
if node.parent.type not in self.skipParensParents:
right = self.pushRight()
right.fs = '(' + FS.lr + ')'
return right
return self

def acceptThisConstructorCall(self, node, memo):
""" Accept and process a 'this(...)' constructor call. """
Expand Down
11 changes: 11 additions & 0 deletions test/Expr2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Expr2 {
public static void main(String[] args) {
int a = 1;
int b = 2;
int c = 3;
int radius = 4;
int y = (radius*radius*a*(a + radius)*radius*b*b) / (c*c+a*a+b*b);
System.out.println(y);

}
}

0 comments on commit ad5b3fe

Please sign in to comment.