示例#1
0
    def render(self, indent: int = 0) -> Iterable[Line]:
        for index, statements in enumerate(self.items):
            yield Line("or" if index else "either", indent)
            for statement in statements:
                yield from statement.render(indent + 2)

        yield Line("end either;", indent)
示例#2
0
    def render(self, indent: int = 0) -> Iterable[Line]:
        args = ", ".join(str(arg) for arg in self.args)
        yield Line(f"procedure {str(self.name)}({args})", indent)

        if self.variables is not None:
            yield Line(str(self.variables), indent)

        yield from self.body.render(indent)
        yield Line("end procedure;", indent)
示例#3
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line()
     yield Line("define", indent)
     yield from (
         Line(line, indent + 2)
         for item in self.items
         for line in item.splitlines()
     )
     yield Line("end define;", indent)
示例#4
0
    def render(self, indent: int = 0) -> Iterable[Line]:
        declarations = ", ".join(
            str(declaration) for declaration in self.declarations)
        yield Line(f"with {declarations}", indent)

        yield Line("do", indent)
        for statement in self.statements:
            yield from statement.render(indent + 2)
        yield Line("end with;", indent)
示例#5
0
文件: if_.py 项目: jessemyers/pluscal
    def render(self, indent: int = 0) -> Iterable[Line]:
        yield from self.if_clause.render(indent)

        for elsif_clause in self.elsif_clauses:
            yield from elsif_clause.render(indent)

        if self.else_:
            yield Line("else", indent)
            for statement in self.else_:
                yield from statement.render(indent + 2)

        yield Line(f"end if;", indent)
示例#6
0
def test_line():
    line = Line("foo", 2)

    assert_that(
        str(line),
        is_(equal_to("  foo")),
    )
示例#7
0
    def render(self, indent: int = 0) -> Iterable[Line]:
        if self.label is not None:
            yield Line(f"{str(self.label)}:", indent)
            extra_indent = 2
        else:
            extra_indent = 0

        yield from self.value.render(indent=indent + extra_indent)
示例#8
0
    def render(self, indent: int = 0) -> Iterable[Line]:
        algorithm = "fair algorithm" if self.fair else "algorithm"
        yield Line(f"--{algorithm} {str(self.name)}", indent)

        if self.variables:
            yield from self.variables.render(indent)

        if self.definitions:
            yield from self.definitions.render(indent)

        if self.macros:
            yield from self.macros.render(indent)

        if self.procedures:
            yield from self.procedures.render(indent)

        if isinstance(self.body, AlgorithmBody):
            yield Line()

        yield from self.body.render(indent)

        yield Line("end algorithm", indent)
示例#9
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line(f"call {self.value}", indent)
示例#10
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line(f"print {str(self.value)};", indent)
示例#11
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line("return;", indent)
示例#12
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line("skip;", indent)
示例#13
0
文件: if_.py 项目: jessemyers/pluscal
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line(f"{self.clause_type} {str(self.condition)} then", indent)
     for statement in self.statements:
         yield from statement.render(indent + 2)
示例#14
0
    def render(self, indent: int = 0) -> Iterable[Line]:
        values = ", ".join(str(item) for item in self.items)
        variable = "variables" if len(self.items) > 1 else "variable"

        yield Line(f"{variable} {values};", indent)
示例#15
0
    def render(self, indent: int = 0) -> Iterable[Line]:
        args = ", ".join(str(arg) for arg in self.args)

        yield Line(f"macro {str(self.name)}({args})", indent)
        yield from self.body.render(indent)
        yield Line("end macro;", indent)
示例#16
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line("begin", indent)
     for item in self.items:
         yield from item.render(indent + 2)
示例#17
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line(" || ".join(str(item) for item in self.items) + ";", indent)
示例#18
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line(self.value, indent)
示例#19
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     yield Line(f"while {str(self.condition)} do", indent)
     for statement in self.statements:
         yield from statement.render(indent + 2)
     yield Line("end while;", indent)
示例#20
0
 def render(self, indent: int = 0) -> Iterable[Line]:
     for item in self.items:
         yield Line()
         yield from item.render(indent)