python: improve handling of formulas

* src/misc/escape.hh, src/misc/escape.cc (escape_latex): New function.
* src/ltlvisit/tostring.cc: Escape atomic proposition in LaTeX output.
* wrap/python/spot.py: Make it easy to output formulas in different
syntaxes.  Also allow the AST to be shown.
* wrap/python/spot_impl.i: Catch std::runtime_error.
* wrap/python/tests/formulas.ipynb: New file.
* wrap/python/tests/Makefile.am: Add it.
This commit is contained in:
Alexandre Duret-Lutz 2015-03-11 19:41:24 +01:00
parent a6dbf5cf5e
commit 2362b9ab68
7 changed files with 667 additions and 35 deletions

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2012, 2013 Laboratoire de Recherche et Developpement de
// Copyright (C) 2012, 2013, 2015 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE)
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -34,14 +34,44 @@ namespace spot
std::ostream&
escape_rfc4180(std::ostream& os, const std::string& str)
{
for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
switch (*i)
for (auto i: str)
switch (i)
{
case '"':
os << "\"\"";
break;
default:
os << *i;
os << i;
break;
}
return os;
}
std::ostream&
escape_latex(std::ostream& os, const std::string& str)
{
for (auto i: str)
switch (i)
{
case '~':
os << "\\textasciitilde";
break;
case '^':
os << "\\textasciicircum";
break;
case '\\':
os << "\\textbackslash";
break;
case '&':
case '%':
case '$':
case '#':
case '_':
case '{':
case '}':
os << '\\';
default:
os << i;
break;
}
return os;
@ -50,8 +80,8 @@ namespace spot
std::ostream&
escape_str(std::ostream& os, const std::string& str)
{
for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
switch (*i)
for (auto i: str)
switch (i)
{
case '\\':
os << "\\\\";
@ -63,7 +93,7 @@ namespace spot
os << "\\n";
break;
default:
os << *i;
os << i;
break;
}
return os;

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2013 Laboratoire de Recherche et
// Copyright (C) 2011, 2012, 2013, 2015 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -39,6 +39,13 @@ namespace spot
SPOT_API std::ostream&
escape_rfc4180(std::ostream& os, const std::string& str);
/// \brief Escape special LaTeX characters.
///
/// The following characters are rewritten:
/// <code>& % $ # _ { } ~ ^ \\</code>
SPOT_API std::ostream&
escape_latex(std::ostream& os, const std::string& str);
/// \brief Escape characters <code>"</code>, <code>\\</code>, and
/// <code>\\n</code> in \a str.
SPOT_API std::ostream&