@@ -448,41 +448,39 @@ def acceptForEach(self, node, memo):
448448
449449 def acceptIf (self , node , memo ):
450450 """ Accept and process an if statement. """
451- # the parser will feed us one of three forms:
452- # bare if: PARENTESIZED_EXPR - BLOCK_SCOPE
453- # if with else: PARENTESIZED_EXPR - BLOCK_SCOPE - BLOCK_SCOPE
454- # if with else if: PARENTESIZED_EXPR - BLOCK_SCOPE - IF
455451 children = node .children
456452 ifStat = self .factory .statement ('if' , fs = FS .lsrc , parent = self )
457453 ifStat .expr .walk (children [0 ], memo )
458- if node .children [1 ].type == tokens .BLOCK_SCOPE :
459- ifBlock = self .factory .methodContent (parent = self )
460- ifBlock .walk (node .children [1 ], memo )
461- elif node .children [1 ].type == tokens .EXPR :
454+
455+ if node .children [1 ].type == tokens .EXPR :
462456 ifBlock = self .factory .expr (parent = ifStat )
463457 ifBlock .walk (node .children [1 ], memo )
458+ else :
459+ ifBlock = self .factory .methodContent (parent = self )
460+ ifBlock .walk (node .children [1 ], memo )
461+
464462 if len (children ) == 3 :
465463 nextNode = children [2 ]
466464 nextType = nextNode .type
467465
468466 while nextType == tokens .IF :
469467 nextStat = self .factory .statement ('elif' , fs = FS .lsrc , parent = self )
470468 nextStat .expr .walk (nextNode .children [0 ], memo )
471- if nextNode .children [1 ].type == tokens .BLOCK_SCOPE :
472- nextBlock = self .factory .methodContent (parent = self )
473- else :
469+ if nextNode .children [1 ].type == tokens .EXPR :
474470 nextBlock = self .factory .expr (parent = nextStat )
471+ else :
472+ nextBlock = self .factory .methodContent (parent = self )
475473 nextBlock .walk (nextNode .children [1 ], memo )
476474 nextNode = nextNode .children [2 ]
477475 nextType = nextNode .type
478476
479- if nextType == tokens .BLOCK_SCOPE :
480- self .factory .statement ('else' , fs = FS .lc , parent = self )
481- self .factory .methodContent (parent = self ).walk (nextNode , memo )
482- elif nextType == tokens .EXPR :
477+ if nextType == tokens .EXPR :
483478 elseStat = self .factory .statement ('else' , fs = FS .lc , parent = self )
484479 elseBlock = self .factory .expr (parent = elseStat )
485480 elseBlock .walk (nextNode , memo )
481+ else : # nextType != tokens.BLOCK_SCOPE:
482+ self .factory .statement ('else' , fs = FS .lc , parent = self )
483+ self .factory .methodContent (parent = self ).walk (nextNode , memo )
486484
487485
488486 def acceptSwitch (self , node , memo ):
@@ -582,6 +580,7 @@ def acceptReturn(self, node, memo):
582580 if node .children :
583581 expr .fs , expr .right = FS .lsr , self .factory .expr (parent = expr )
584582 expr .right .walk (node , memo )
583+ return expr
585584
586585 def acceptWhile (self , node , memo ):
587586 """ Accept and process a while block. """
0 commit comments