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;"""))), )
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(), )
def build(self) -> Stmt: return Stmt( label=to_label(self.label), value=While( condition=Expr(self.condition), statements=self.statements, ), )
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 ], ), )
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, ), )
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
def build(self) -> PVarDecl: return PVarDecl( name=Variable(self.name), value=Expr(self.value) if self.value else None, )
def build(self) -> ElsifClause: return ElsifClause( Expr(self.condition), self.statements, )
def with_(self, *args: str) -> "AbstractCallBuilder": self.args.extend(Expr(arg) for arg in args) return self
def build(self) -> Stmt: return Stmt( label=to_label(self.label), value=Assert(Expr(self.value)), )
def eq_(self, value: str) -> "VariableBuilder": self.type = DeclType.EQUALS self.value = Expr(value) return self
def in_set(self, *args: str) -> "VariableBuilder": self.type = DeclType.IN self.value = Expr(f"{{{', '.join(quote(item) for item in args)}}}") return self
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
def in_(self, value: str) -> "VariableBuilder": self.type = DeclType.IN self.value = Expr(value) return self