Skip to content

Commit 10bec15

Browse files
authored
Print support for SEXPR (#97)
1 parent ed25955 commit 10bec15

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

cvc5_pythonic_api/cvc5_pythonic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,16 @@ def FreshConst(sort, prefix="c"):
13121312
return Const(name, sort)
13131313

13141314

1315+
def Sexpr(*args):
1316+
"""Create an SEXPR term.
1317+
1318+
>>> p, q, r = Bools('p q r')
1319+
>>> Sexpr(p, q, r)
1320+
(p q r)
1321+
"""
1322+
return _nary_kind_builder(Kind.SEXPR, *args)
1323+
1324+
13151325
#########################################
13161326
#
13171327
# Booleans

cvc5_pythonic_api/cvc5_pythonic_printer.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,21 @@ def pp_select(self, a, d, xs):
10801080
arg1_pp, indent(2, compose(to_format("["), arg2_pp, to_format("]")))
10811081
)
10821082

1083+
def pp_sexpr(self, a, d, xs):
1084+
r = []
1085+
sz = 0
1086+
for child in a.children():
1087+
r.append(self.pp_expr(child, d + 1, xs))
1088+
sz = sz + 1
1089+
if sz > self.max_args:
1090+
r.append(self.pp_ellipses())
1091+
break
1092+
return group(
1093+
indent(
1094+
len("("), compose(to_format("("), seq(r, " ", False), to_format(")"))
1095+
)
1096+
)
1097+
10831098
def pp_unary_param(self, a, d, xs, param_on_right):
10841099
p = a.ast.getOp()[0].toPythonObj()
10851100
arg = self.pp_expr(a.arg(0), d + 1, xs)
@@ -1194,6 +1209,8 @@ def pp_app(self, a, d, xs):
11941209
return self.pp_uf_apply(a, d, xs)
11951210
elif k in [Kind.APPLY_CONSTRUCTOR, Kind.APPLY_SELECTOR, Kind.APPLY_TESTER]:
11961211
return self.pp_dt_apply(a, d, xs)
1212+
elif k == Kind.SEXPR:
1213+
return self.pp_sexpr(a, d, xs)
11971214
else:
11981215
return self.pp_prefix(a, d, xs)
11991216

test/pgm_outputs/example_sexpr.py.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(x y z)

test/pgms/example_sexpr.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from cvc5_pythonic_api import *
2+
x = Int("x")
3+
y = Int("y")
4+
z = Int("z")
5+
print(Sexpr(x, y, z))

0 commit comments

Comments
 (0)