def __str__(self) -> str: result = "" for condition, statements in self.condition_statements: if not result: result = f"if {condition} then\n" else: result += f"elsif {condition} then\n" for statement in statements: result += indent(str(statement), 3) + "\n" if self.else_statements: result += "else\n" for statement in self.else_statements: result += indent(str(statement), 3) + "\n" result += "end if;" return result
def __str__(self) -> str: result = "" for condition, statements in self.condition_statements: c = (f" {condition} " if str(condition).count("\n") == 0 else f"\n{indent(str(condition), 2)}\n") if not result: result = f"if{c}then\n" else: result += f"elsif{c}then\n" for statement in statements: result += indent(str(statement), 3) + "\n" if self.else_statements: result += "else\n" for statement in self.else_statements: result += indent(str(statement), 3) + "\n" result += "end if;" return result
def declarative_items(declarations: List[Declaration], private: bool = False) -> str: result = "\n\n".join( indent(str(d), 3) for d in unique(declarations) if str(d)) if result: result = f"private\n\n{result}" if private else result result += "\n\n" return result
def __str__(self) -> str: grouped_cases = [(" | ".join(str(c) for c, _ in choices), statements) for statements, choices in itertools.groupby( self.case_statements, lambda x: x[1])] cases = "".join([ "\nwhen {} =>\n{}".format( choice, indent("\n".join(str(s) for s in statements), 3)) for choice, statements in grouped_cases ]) return f"case {self.control_expression} is{indent(cases, 3)}\nend case;"
def __str__(self) -> str: grouped_cases = [ (" | ".join(str(c) for c, _ in choices), expr) for expr, choices in itertools.groupby(self.case_statements, lambda x: x[1]) ] cases = indent( ",".join( [f"\nwhen {choice} =>\n{indent(str(expr), 3)}" for choice, expr in grouped_cases] ), 4, ) return f"(case {self.control_expression} is{cases})"
def _statements(self) -> str: return "\n".join(indent(str(s), 3) for s in self.statements)
def _declarations(self) -> str: return "".join( indent(f"{declaration}\n", 3) for declaration in self.declarations)
def type_definition(self) -> str: components = ((indent("\n".join(map(str, self.components)), 6) + "\n") if self.components else "") variant_part = indent(str(self.variant_part), 6) if self.variant_part else "" return f"\n" f" record\n" f"{components}" f"{variant_part}" f" end record"
def __str__(self) -> str: choices = " | ".join(map(str, self.discrete_choices)) components = indent("\n".join(map(str, self.components)), 6) return f" when {choices} =>\n{components}"
def aspect_specification(aspects: Sequence[Aspect]) -> str: if not aspects: return "" return " with\n" + ",\n".join(indent(str(aspect), 2) for aspect in aspects)
def __str__(self) -> str: return ( f"(for {self.quantifier} {self.parameter_name} {self.keyword} {self.iterable} =>\n" + indent(str(self.predicate), 4) + ")" )