Better formula I/O for ipython.
* src/ltlparse/public.hh, src/ltlparse/ltlparse.yy, src/ltlparse/ltlscan.ll (parse_error): New class. (parse_formula): New function that raises a parse_error exception on error. * src/ltlvisit/tostring.hh, src/ltlvisit/tostring.cc: (to_sclatex_string): New method. * wrap/python/spot.i: Catch the parser_error exception, and use the to_sclatex_string for MathJax rendering. * wrap/python/tests/run.in: Start ipython on demand.
This commit is contained in:
parent
6d7c258fd7
commit
ae35cc29f5
7 changed files with 150 additions and 16 deletions
|
|
@ -31,6 +31,7 @@
|
|||
%include "std_shared_ptr.i"
|
||||
%include "std_string.i"
|
||||
%include "std_list.i"
|
||||
%include "exception.i"
|
||||
|
||||
// git grep 'typedef.*std::shared_ptr' | grep -v const
|
||||
// sed 's/.*<\(.*\)>.*/%shared_ptr(spot::\1)/g'
|
||||
|
|
@ -172,6 +173,19 @@ using namespace spot;
|
|||
};
|
||||
%apply char** OUTPUT { char** err };
|
||||
|
||||
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
}
|
||||
catch (const spot::ltl::parse_error& e)
|
||||
{
|
||||
std::string er("\n");
|
||||
er += e.what();
|
||||
SWIG_exception(SWIG_SyntaxError, er.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// False and True cannot be redefined in Python3, even in a class.
|
||||
// Spot uses these in an enum of the constant class.
|
||||
%rename(FalseVal) False;
|
||||
|
|
@ -286,12 +300,12 @@ namespace spot {
|
|||
|
||||
size_t __hash__() { return self->hash(); }
|
||||
|
||||
std::string
|
||||
__str__(void)
|
||||
std::string __repr__() { return spot::ltl::to_string(self); }
|
||||
std::string _repr_latex_()
|
||||
{
|
||||
return spot::ltl::to_string(self);
|
||||
return std::string("$") + spot::ltl::to_sclatex_string(self) + '$';
|
||||
}
|
||||
|
||||
std::string __str__() { return spot::ltl::to_string(self); }
|
||||
}
|
||||
|
||||
%nodefaultctor std::ostream;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ case $1 in
|
|||
PYTHONPATH=$pypath DYLD_LIBRARY_PATH=$modpath exec @PYTHON@ "$@";;
|
||||
*.test)
|
||||
exec sh -x "$@";;
|
||||
ipython*)
|
||||
PYTHONPATH=$pypath DYLD_LIBRARY_PATH=$modpath exec "$@";;
|
||||
*)
|
||||
echo "Unknown extension" >&2
|
||||
exit 2;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue