Skip to content

Commit

Permalink
coredsl2 writer: surround operands in parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed May 15, 2024
1 parent 84ad68c commit 8c99fdc
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions seal5/backends/coredsl2/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,31 @@ def operation(self: behav.Operation, writer):

def binary_operation(self: behav.BinaryOperation, writer):
# print("binary_operation")
writer.write("(")
self.left = self.left.generate(writer)
writer.write(f" {self.op.value} ")
writer.write(f") {self.op.value} (")
self.right = self.right.generate(writer)
writer.write(")")


def slice_operation(self: behav.SliceOperation, writer):
# print("slice_operation")
self.expr = self.expr.generate(writer)
writer.write("[")
writer.write("[(")
self.left = self.left.generate(writer)
writer.write(":")
writer.write("):(")
self.right = self.right.generate(writer)
writer.write("]")
writer.write(")]")


def concat_operation(self: behav.ConcatOperation, writer):
# print("concat_operation")
# TODO: only add () where required
writer.write("(")
self.left = self.left.generate(writer)
writer.write(" :: ")
writer.write(") :: (")
self.right = self.right.generate(writer)
writer.write(")")


def number_literal(self: behav.IntLiteral, writer):
Expand Down Expand Up @@ -128,11 +133,13 @@ def loop(self: behav.Loop, writer):

def ternary(self: behav.Ternary, writer):
# print("ternary")
writer.write("(")
self.cond.generate(writer)
writer.write(" ? ")
writer.write(") ? (")
self.then_expr.generate(writer)
writer.write(" : ")
writer.write(") : (")
self.else_expr.generate(writer)
writer.write(")")


def return_(self: behav.Return, writer):
Expand All @@ -147,7 +154,9 @@ def return_(self: behav.Return, writer):
def unary_operation(self: behav.UnaryOperation, writer):
# print("unary_operation")
writer.write(self.op.value)
writer.write("(")
self.right.generate(writer)
writer.write(")")


def named_reference(self: behav.NamedReference, writer):
Expand Down

0 comments on commit 8c99fdc

Please sign in to comment.