Created
May 2, 2012 21:38
-
-
Save Naddiseo/2580705 to your computer and use it in GitHub Desktop.
Potential fix for https://github.com/natural/java2python/issues/15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/java2python/compiler/visitor.py b/java2python/compiler/visitor.py | |
index 3b55e31..4ac6315 100644 | |
--- a/java2python/compiler/visitor.py | |
+++ b/java2python/compiler/visitor.py | |
@@ -470,7 +470,8 @@ class MethodContent(Base): | |
if len(children) == 3: | |
nextNode = children[2] | |
nextType = nextNode.type | |
- | |
+ | |
+ | |
while nextType == tokens.IF: | |
nextStat = self.factory.statement('elif', fs=FS.lsrc, parent=self) | |
nextStat.expr.walk(nextNode.children[0], memo) | |
@@ -479,13 +480,20 @@ class MethodContent(Base): | |
else: | |
nextBlock = self.factory.methodContent(parent=self) | |
nextBlock.walk(nextNode.children[1], memo) | |
- nextNode = nextNode.children[2] | |
- nextType = nextNode.type | |
+ try: | |
+ nextNode = nextNode.children[2] | |
+ nextType = nextNode.type | |
+ except IndexError: | |
+ nextType = None # A missing else | |
+ break | |
+ | |
if nextType == tokens.EXPR: | |
elseStat = self.factory.statement('else', fs=FS.lc, parent=self) | |
elseBlock = self.factory.expr(parent=elseStat) | |
elseBlock.walk(nextNode, memo) | |
+ elif nextType is None: # elseif without an else | |
+ pass | |
else: # nextType != tokens.BLOCK_SCOPE: | |
self.factory.statement('else', fs=FS.lc, parent=self) | |
self.factory.methodContent(parent=self).walk(nextNode, memo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment