Skip to content

Commit 3a2de1e

Browse files
authored
Adding Strings and Sequences to the Pythonic API (#86)
1 parent 81f38c9 commit 3a2de1e

23 files changed

Lines changed: 998 additions & 34 deletions

cvc5_pythonic_api/cvc5_pythonic.py

Lines changed: 817 additions & 22 deletions
Large diffs are not rendered by default.

cvc5_pythonic_api/cvc5_pythonic_printer.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ def _assert(cond, msg):
9696
Kind.SEQ_UNIT: "Unit",
9797
Kind.SEQ_CONTAINS: "Contains",
9898
Kind.SEQ_REPLACE: "Replace",
99+
Kind.SEQ_EXTRACT: "Extract",
99100
Kind.SEQ_AT: "At",
100-
Kind.SEQ_NTH: "Nth",
101+
Kind.SEQ_NTH: "[]",
101102
Kind.SEQ_INDEXOF: "IndexOf",
103+
Kind.SEQ_UPDATE: "Update",
102104
Kind.SEQ_LENGTH: "Length",
103105
Kind.SET_SUBSET: "IsSubset",
104106
Kind.SET_MINUS: "SetDifference",
@@ -110,14 +112,21 @@ def _assert(cond, msg):
110112
Kind.SET_MEMBER: "IsMember",
111113
Kind.STRING_TO_INT: "StrToInt",
112114
Kind.STRING_FROM_INT: "IntToStr",
113-
# Kind.Seq_in_re: "InRe",
114-
# Kind.Seq_to_re: "Re",
115+
Kind.STRING_FROM_CODE: "StringFromCode",
116+
Kind.STRING_TO_REGEXP: "StringToRegexp",
117+
Kind.STRING_IN_REGEXP: "StringInRegexp",
118+
Kind.STRING_TO_CODE: "StringToCode",
119+
Kind.REGEXP_LOOP: "RegexpLoop",
120+
Kind.REGEXP_CONCAT: "RegexpConcat",
121+
Kind.REGEXP_OPT: "RegexpOpt",
115122
Kind.REGEXP_PLUS: "Plus",
116123
Kind.REGEXP_STAR: "Star",
117124
Kind.REGEXP_UNION: "Union",
118125
Kind.REGEXP_RANGE: "Range",
119126
Kind.REGEXP_INTER: "Intersect",
120127
Kind.REGEXP_COMPLEMENT: "Complement",
128+
Kind.REGEXP_ALL: "Full",
129+
Kind.REGEXP_NONE: "RegexpNone",
121130
Kind.FLOATINGPOINT_IS_NAN: "fpIsNaN",
122131
Kind.FLOATINGPOINT_IS_INF: "fpIsInf",
123132
Kind.FLOATINGPOINT_IS_ZERO: "fpIsZero",
@@ -140,6 +149,15 @@ def _assert(cond, msg):
140149
Kind.ARCCOTANGENT: "Arccotangent",
141150
Kind.PI: "Pi",
142151
Kind.EXPONENTIAL: "Exponential",
152+
# Strings
153+
Kind.STRING_SUBSTR: "SubString",
154+
Kind.STRING_CHARAT: "At",
155+
Kind.STRING_CONCAT: "+",
156+
Kind.STRING_LENGTH: "Length",
157+
Kind.STRING_REPLACE: "Replace",
158+
Kind.STRING_UPDATE: "StringUpdate",
159+
Kind.STRING_LEQ: "<=",
160+
Kind.STRING_LT: "<",
143161
}
144162

145163
# List of infix operators
@@ -173,6 +191,9 @@ def _assert(cond, msg):
173191
Kind.BITVECTOR_SHL,
174192
Kind.FINITE_FIELD_ADD,
175193
Kind.FINITE_FIELD_MULT,
194+
Kind.STRING_LT,
195+
Kind.STRING_LEQ,
196+
Kind.SEQ_NTH,
176197
]
177198

178199
_cvc5_unary = [Kind.NEG, Kind.BITVECTOR_NEG, Kind.BITVECTOR_NOT, Kind.FINITE_FIELD_NEG]
@@ -395,6 +416,8 @@ def _op_name(a):
395416
Kind.UNINTERPRETED_SORT_VALUE,
396417
Kind.PI,
397418
Kind.CONST_INTEGER,
419+
Kind.CONST_STRING,
420+
Kind.CONST_SEQUENCE,
398421
]:
399422
return str(a.ast)
400423
if k == Kind.INTERNAL_KIND:
@@ -786,7 +809,7 @@ def pp_algebraic(self, a):
786809
return to_format(a.as_decimal(self.precision))
787810

788811
def pp_string(self, a):
789-
return to_format('"' + a.as_string() + '"')
812+
return to_format(str(a.ast))
790813

791814
def pp_bv(self, a):
792815
return to_format(a.as_string())
@@ -1127,8 +1150,8 @@ def pp_app(self, a, d, xs):
11271150
return self.pp_fp_value(a)
11281151
elif cvc.is_fp(a):
11291152
return self.pp_fp(a, d, xs)
1130-
# elif cvc.is_string_value(a):
1131-
# return self.pp_string(a)
1153+
elif cvc.is_string_value(a):
1154+
return self.pp_string(a)
11321155
elif cvc.is_const(a):
11331156
return self.pp_const(a)
11341157
else:

test/pgm_outputs/example_re.py.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
True
2+
[a = "a"]
3+
no solution
4+
[a = ""]
5+
[a = ""]
6+
[a = "a"]
7+
[a = "a"]
8+
[a = "A"]
9+
[a = "a"]
10+
[a = ""]
11+
no solution
12+
[a = ""]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[s = "ab"]
2+
[s = "a"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
False
2+
[s = (seq.unit 1)(), t = (seq.unit 2)()]
3+
[s = (seq.unit (- 1))(), t = (seq.unit (- 1))()]
4+
[s = (as seq.empty (Seq Int))()]
5+
[s = (as seq.empty (Seq Int))()]
6+
[s = (seq.++ (seq.unit 1) (seq.unit 2))()]
7+
[s = (as seq.empty (Seq Int))()]
8+
[s = (seq.++ (seq.unit 1) (seq.unit 2))()]
9+
[s = (seq.++ (seq.unit 1) (seq.unit 1))(), t = (seq.++ (seq.unit 1) (seq.unit 1))()]
10+
[s = (as seq.empty (Seq Int))(), t = (as seq.empty (Seq Int))(), u = (as seq.empty (Seq Int))()]
11+
[s = (seq.++ (seq.unit (- 2)) (seq.unit (- 1)))(), t = (seq.unit (- 1))()]
12+
[s = (seq.++ (seq.unit (- 3)) (seq.unit (- 2)) (seq.unit 4))(), t = (seq.unit 4)()]
13+
no solution
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
True
2+
[s = (seq.++ (seq.unit 1) (seq.unit 2))(), t = (as seq.empty (Seq Int))()]
3+
[a = "heAAA"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
True
2+
True
3+
[B = "", trying = ""]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[a = "aAAAA"]
2+
[a = "?"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[a = "", b = "\u{0}", c = "\u{1}"]
2+
[a = "A", b = "", c = ""]
3+
[a = "", b = "", c = ""]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[a = "", b = ""]
2+
[a = "hello", b = ""]
3+
no solution

0 commit comments

Comments
 (0)