示例#1
0
def test_body_builder():
    builder = BodyBuilder().do(
        Print(Expr("a")),
        Stmt(Print(Expr("b"))),
        PrintBuilder("c", label="Foo"),
    )

    assert_that(
        str(builder),
        is_(equal_to(dedent("""\
            begin
              print a;
              print b;
              Foo:
                print c;"""))),
    )
示例#2
0
 def build(self) -> Process:
     return Process(
         name=Name(self.name),
         type=self.type,
         value=Expr(self.value),
         variables=self.variables.build(),
         body=self.body.build(),
     )
示例#3
0
 def build(self) -> Stmt:
     return Stmt(
         label=to_label(self.label),
         value=While(
             condition=Expr(self.condition),
             statements=self.statements,
         ),
     )
示例#4
0
 def build(self) -> Stmt:
     return Stmt(
         label=to_label(self.label),
         value=Assign(items=[
             Assignment(
                 left=to_lhs(left),
                 right=Expr(right),
             ) for left, right in [(self.left, self.right)] + self.items
         ], ),
     )
示例#5
0
 def build(self) -> Stmt:
     return Stmt(
         label=to_label(self.label),
         value=If(
             IfClause(
                 Expr(self.condition),
                 self.statements,
             ),
             self.elsif_clauses,
             self.otherwise if self.otherwise else None,
         ),
     )
示例#6
0
 def __getitem__(self, key: Union[str, Tuple[str, ...]]) -> "LHSBuilder":
     if isinstance(key, tuple):
         self.items.append([Expr(arg) for arg in key])
     else:
         self.items.append([Expr(key)])
     return self
示例#7
0
 def build(self) -> PVarDecl:
     return PVarDecl(
         name=Variable(self.name),
         value=Expr(self.value) if self.value else None,
     )
示例#8
0
 def build(self) -> ElsifClause:
     return ElsifClause(
         Expr(self.condition),
         self.statements,
     )
示例#9
0
 def with_(self, *args: str) -> "AbstractCallBuilder":
     self.args.extend(Expr(arg) for arg in args)
     return self
示例#10
0
 def build(self) -> Stmt:
     return Stmt(
         label=to_label(self.label),
         value=Assert(Expr(self.value)),
     )
示例#11
0
 def eq_(self, value: str) -> "VariableBuilder":
     self.type = DeclType.EQUALS
     self.value = Expr(value)
     return self
示例#12
0
 def in_set(self, *args: str) -> "VariableBuilder":
     self.type = DeclType.IN
     self.value = Expr(f"{{{', '.join(quote(item) for item in args)}}}")
     return self
示例#13
0
 def in_range(self, left: Union[int, str], right: Union[int, str]) -> "VariableBuilder":
     self.type = DeclType.IN
     self.value = Expr(f"{left}..{right}")
     return self
示例#14
0
 def in_(self, value: str) -> "VariableBuilder":
     self.type = DeclType.IN
     self.value = Expr(value)
     return self