python: more conventional __repr__ for several types
* NEWS: Mention the change. * python/spot/__init__.py: Add _repr_latex_ for twa_word, and remove __repr__ and __str__ for atomic_prop_set. * python/spot/impl.i: Implement __repr__ and __str__ for atomic_prop_set. Fix __repr__ for trival, acc_code, acc_cond, mark_t. Remove __repr__ for twa_run and twa_word. * tests/python/acc_cond.ipynb, tests/python/accparse.ipynb, tests/python/atva16-fig2a.ipynb, tests/python/automata.ipynb, tests/python/bdditer.py, tests/python/contains.ipynb, tests/python/gen.ipynb, tests/python/highlighting.ipynb, tests/python/ltlsimple.py, tests/python/ltsmin-dve.ipynb, tests/python/product.ipynb, tests/python/relabel.py, tests/python/satmin.ipynb tests/python/stutter-inv.ipynb, tests/python/word.ipynb: Adjust test cases. * tests/python/formulas.ipynb: Add test for atomic_prop_set.
This commit is contained in:
parent
c3b7a691e4
commit
60296317c7
19 changed files with 686 additions and 700 deletions
|
|
@ -352,19 +352,6 @@ class formula:
|
|||
|
||||
@_extend(atomic_prop_set)
|
||||
class atomic_prop_set:
|
||||
def __repr__(self):
|
||||
res = '{'
|
||||
comma = ''
|
||||
for ap in self:
|
||||
res += comma
|
||||
comma = ', '
|
||||
res += '"' + ap.ap_name() + '"'
|
||||
res += '}'
|
||||
return res
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
def _repr_latex_(self):
|
||||
res = '$\{'
|
||||
comma = ''
|
||||
|
|
@ -1147,6 +1134,22 @@ formula.show_mp_hierarchy = show_mp_hierarchy
|
|||
|
||||
@_extend(twa_word)
|
||||
class twa_word:
|
||||
def _repr_latex_(self):
|
||||
bd = self.get_dict()
|
||||
res = '$'
|
||||
for idx, letter in enumerate(self.prefix):
|
||||
if idx:
|
||||
res += '; '
|
||||
res += bdd_to_formula(letter, bd).to_str('j')
|
||||
if len(res) > 1:
|
||||
res += '; ';
|
||||
res += '\\mathsf{cycle}\\{';
|
||||
for idx, letter in enumerate(self.cycle):
|
||||
if idx:
|
||||
res += '; '
|
||||
res += bdd_to_formula(letter, bd).to_str('j')
|
||||
return res + '\\}$'
|
||||
|
||||
def as_svg(self):
|
||||
"""
|
||||
Build an SVG picture representing the word as a collection of
|
||||
|
|
|
|||
|
|
@ -669,13 +669,42 @@ def state_is_accepting(self, src) -> "bool":
|
|||
%include <spot/taalgos/stats.hh>
|
||||
%include <spot/taalgos/minimize.hh>
|
||||
|
||||
%extend std::set<spot::formula> {
|
||||
std::string __str__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << '{';
|
||||
const char* sep = "";
|
||||
for (spot::formula s: *self)
|
||||
{
|
||||
os << sep << '"' << spot::escape_str(spot::str_psl(s)) << '"';
|
||||
sep = ", ";
|
||||
}
|
||||
os << '}';
|
||||
return os.str();
|
||||
}
|
||||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "spot.atomic_prop_set([";
|
||||
const char* sep = "";
|
||||
for (spot::formula s: *self)
|
||||
{
|
||||
os << sep
|
||||
<< "spot.formula(\"" << spot::escape_str(spot::str_psl(s)) << "\")";
|
||||
sep = ", ";
|
||||
}
|
||||
os << "])";
|
||||
return os.str();
|
||||
}
|
||||
}
|
||||
|
||||
%extend spot::acc_cond::rs_pair {
|
||||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "spot.rs_pair(fin=[";
|
||||
char* sep = "";
|
||||
const char* sep = "";
|
||||
for (unsigned s: self->fin.sets())
|
||||
{
|
||||
os << sep << s;
|
||||
|
|
@ -696,9 +725,11 @@ def state_is_accepting(self, src) -> "bool":
|
|||
%extend spot::trival {
|
||||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *self;
|
||||
return os.str();
|
||||
if (self->is_true())
|
||||
return "spot.trival(True)";
|
||||
if (self->is_false())
|
||||
return "spot.trival(False)";
|
||||
return "spot.trival_maybe()";
|
||||
}
|
||||
|
||||
std::string __str__()
|
||||
|
|
@ -752,7 +783,9 @@ def state_is_accepting(self, src) -> "bool":
|
|||
unsigned __len__() { return self->size(); }
|
||||
formula __getitem__(unsigned pos) { return (*self)[pos]; }
|
||||
|
||||
std::string __repr__() { return spot::str_psl(*self); }
|
||||
std::string __repr__() {
|
||||
return "spot.formula(\"" + spot::escape_str(spot::str_psl(*self)) + "\")";
|
||||
}
|
||||
std::string __str__() { return spot::str_psl(*self); }
|
||||
}
|
||||
|
||||
|
|
@ -929,7 +962,7 @@ def state_is_accepting(self, src) -> "bool":
|
|||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *self;
|
||||
os << "spot.acc_code(\"" << *self << "\")";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
@ -951,7 +984,14 @@ def state_is_accepting(self, src) -> "bool":
|
|||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *self;
|
||||
os << "spot.mark_t([";
|
||||
const char* sep = "";
|
||||
for (unsigned s: self->sets())
|
||||
{
|
||||
os << sep << s;
|
||||
sep = ", ";
|
||||
}
|
||||
os << "])";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
@ -967,7 +1007,8 @@ def state_is_accepting(self, src) -> "bool":
|
|||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *self;
|
||||
os << "spot.acc_cond(" << self->num_sets() << ", \""
|
||||
<< self->get_acceptance() << "\")";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
@ -980,13 +1021,6 @@ def state_is_accepting(self, src) -> "bool":
|
|||
}
|
||||
|
||||
%extend spot::twa_run {
|
||||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *self;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string __str__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
|
|
@ -996,13 +1030,6 @@ def state_is_accepting(self, src) -> "bool":
|
|||
}
|
||||
|
||||
%extend spot::twa_word {
|
||||
std::string __repr__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *self;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string __str__()
|
||||
{
|
||||
std::ostringstream os;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue