@@ -46,7 +46,7 @@ def insertComments(self, tmpl, tree, index, memo): |
46 | 46 | """ Add comments to the template from tokens in the tree. """ |
47 | 47 | prefix = self.config.last('commentPrefix', '# ') |
48 | 48 | cache, parser, comTypes = memo.comments, tree.parser, tokens.commentTypes |
49 | | - comNew = lambda t:t.type in comTypes and t.index not in cache |
| 49 | + comNew = lambda t:t.type in comTypes and (t.index not in cache) |
50 | 50 |
|
51 | 51 | for tok in ifilter(comNew, parser.input.tokens[memo.last:index]): |
52 | 52 | cache.add(tok.index) |
@@ -173,7 +173,7 @@ def nodesToAnnos(self, branch, memo): |
173 | 173 | if defKey: |
174 | 174 | deco = self.factory.expr(left=name, fs='@{left}({right})') |
175 | 175 | deco.right = right = self.factory.expr(parent=deco) |
176 | | - right.walk(defKey.firstChild()) |
| 176 | + right.walk(defKey.firstChild(), memo) |
177 | 177 | else: |
178 | 178 | deco = self.factory.expr(left=name, fs='@{left}({right})') |
179 | 179 | arg = deco.right = self.factory.expr(parent=deco) |
@@ -432,17 +432,20 @@ def acceptExpr(self, node, memo): |
432 | 432 |
|
433 | 433 | def acceptFor(self, node, memo): |
434 | 434 | """ Accept and process a 'for' statement. """ |
435 | | - self.walk(node.firstChildOfType(tokens.FOR_INIT)) |
| 435 | + self.walk(node.firstChildOfType(tokens.FOR_INIT), memo) |
436 | 436 | whileStat = self.factory.statement('while', fs=FS.lsrc, parent=self) |
437 | 437 | cond = node.firstChildOfType(tokens.FOR_CONDITION) |
438 | 438 | if not cond.children: |
439 | 439 | whileStat.expr.right = 'True' |
440 | 440 | else: |
441 | | - whileStat.expr.walk(cond) |
| 441 | + whileStat.expr.walk(cond, memo) |
442 | 442 | whileBlock = self.factory.methodContent(parent=self) |
443 | | - whileBlock.walk(node.firstChildOfType(tokens.BLOCK_SCOPE)) |
| 443 | + if not node.firstChildOfType(tokens.BLOCK_SCOPE).children: |
| 444 | + self.factory.expr(left='pass', parent=whileBlock) |
| 445 | + else: |
| 446 | + whileBlock.walk(node.firstChildOfType(tokens.BLOCK_SCOPE), memo) |
444 | 447 | updateStat = self.factory.expr(parent=whileBlock) |
445 | | - updateStat.walk(node.firstChildOfType(tokens.FOR_UPDATE)) |
| 448 | + updateStat.walk(node.firstChildOfType(tokens.FOR_UPDATE), memo) |
446 | 449 |
|
447 | 450 | def acceptForEach(self, node, memo): |
448 | 451 | """ Accept and process a 'for each' style statement. """ |
@@ -505,7 +508,7 @@ def acceptSwitch(self, node, memo): |
505 | 508 | return |
506 | 509 | # we have at least one node... |
507 | 510 | parExpr = self.factory.expr(parent=self) |
508 | | - parExpr.walk(parNode) |
| 511 | + parExpr.walk(parNode, memo) |
509 | 512 | eqFs = FS.l + '==' + FS.r |
510 | 513 | for caseIdx, caseNode in enumerate(caseNodes): |
511 | 514 | isDefault, isFirst = caseNode.type==tokens.DEFAULT, caseIdx==0 |
@@ -519,7 +522,7 @@ def acceptSwitch(self, node, memo): |
519 | 522 |
|
520 | 523 | if not isDefault: |
521 | 524 | right = self.factory.expr(parent=parExpr) |
522 | | - right.walk(caseNode.firstChildOfType(tokens.EXPR)) |
| 525 | + right.walk(caseNode.firstChildOfType(tokens.EXPR), memo) |
523 | 526 | caseExpr.expr.right = self.factory.expr(left=parExpr, right=right, fs=eqFs) |
524 | 527 | caseContent = self.factory.methodContent(parent=self) |
525 | 528 | for child in caseNode.children[1:]: |
|