context.indent += ' '
if_text = 'if'
for i in self[1][0]:
- if isinstance(i, AST.StatementCase):
- cond_expr = AST.ExpressionEqual(
- children = [
- self[0],
- i[0]
- ],
- binary_operator = ' == ',
- precedence = 8
- )
- j = i[1]
- while isinstance(j, AST.StatementCase):
- cond_expr = AST.ExpressionLogicalOr(
+ if (
+ isinstance(i, AST.StatementCase) or
+ isinstance(i, AST.StatementDefault)
+ ):
+ if isinstance(i, AST.StatementCase):
+ cond_expr = AST.ExpressionEqual(
children = [
- cond_expr,
- AST.ExpressionEqual(
+ self[0],
+ i[0]
+ ],
+ binary_operator = ' == ',
+ precedence = 8
+ )
+ j = i[1]
+ else:
+ cond_expr = None
+ j = i[0]
+ if (
+ isinstance(j, AST.StatementCase) or
+ isinstance(j, AST.StatementDefault)
+ ):
+ if isinstance(j, AST.StatementCase):
+ if cond_expr is not None:
+ cond_expr = AST.ExpressionLogicalOr(
children = [
- self[0],
- j[0]
+ cond_expr,
+ AST.ExpressionEqual(
+ children = [
+ self[0],
+ j[0]
+ ],
+ binary_operator = ' == ',
+ precedence = 8
+ )
],
- binary_operator = ' == ',
- precedence = 8
+ binary_operator = ' or ',
+ precedence = 3
)
- ],
- binary_operator = ' or ',
- precedence = 3
+ j = j[1]
+ else:
+ cond_expr = None
+ j = j[0]
+ if cond_expr is not None:
+ assert if_text is not None
+ context.lines.append(
+ '{0:s}{1:s} {2:s}:\n'.format(
+ indent_save,
+ if_text,
+ cond_expr.translate_expression(context, 0)
+ )
)
- j = j[1]
- context.lines.append(
- '{0:s}{1:s} {2:s}:\n'.format(
- indent_save,
- if_text,
- cond_expr.translate_expression(context, 0)
+ if_text = 'elif'
+ else:
+ context.lines.append(
+ '{0:s}else:\n'.format(indent_save)
)
- )
- if_text = 'elif'
+ if_text = None
j.translate_declaration_or_statement(context)
- elif isinstance(i, AST.StatementDefault):
- context.lines.append(
- '{0:s}else:\n'.format(indent_save)
- )
- self[0].translate_declaration_or_statement(context)
else:
i.translate_declaration_or_statement(context)
context.indent = indent_save