Skip to content

Commit d74b09e

Browse files
author
Troy Melhase
committed
Added call to remove leading "if False:pass" lines generated for
switch expressions. Closes natural#9.
1 parent 963c7e6 commit d74b09e

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎lib/sourcetypes.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,19 @@ def setName(self, name):
340340
"""
341341
self.name = name
342342

343+
def fixSwitch(self, block):
344+
lines = self.lines
345+
if (not block in lines) or (block.name != 'if'):
346+
return
347+
i = lines.index(block)
348+
if (len(lines) > i):
349+
first_else = lines[i+1]
350+
if first_else.name != 'elif':
351+
return
352+
lines.remove(first_else)
353+
block.expr = first_else.expr
354+
block.lines = first_else.lines
355+
343356
def I(self, indent):
344357
""" calculated indentation string
345358
@@ -606,6 +619,7 @@ def writeTo(self, output, indent):
606619
self.addSource('pass')
607620
Source.writeTo(self, output, indent+1)
608621

622+
609623

610624
class Statement(Source):
611625
""" Statement -> specialized block type

‎lib/walker.g‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ statement [block]
422422
#("switch" switch_expr = expression[block, False]
423423
(c:case_group[block, switch_expr])*
424424
)
425-
425+
{
426+
block.fixSwitch(switch_block)
427+
}
426428

427429
| {
428430
raise_stat = block.newStatement("raise")

0 commit comments

Comments
 (0)