Commit 53f38c2c authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Implement to_utf8_string().

* src/ltlvisit/tostring.cc, src/ltlvisit/tostring.hh: Here.
* src/ltltest/randltl.cc: Add option -8 to display utf-8 formulae.
* src/ltltest/utf8.test: Test it.
parent 6f291411
// Copyright (C) 2008, 2009, 2011 Laboratoire de Recherche et Développement // -*- coding: utf-8 -*-
// de l'Epita (LRDE). // Copyright (C) 2008, 2009, 2011, 2012 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de // Copyright (C) 2003, 2005 Laboratoire d'Informatique de
// Paris 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC), // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Universit Pierre et Marie Curie. // Université Pierre et Marie Curie.
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
// //
...@@ -47,6 +48,7 @@ syntax(char* prog) ...@@ -47,6 +48,7 @@ syntax(char* prog)
<< " -P generate PSL formulae" << std::endl << " -P generate PSL formulae" << std::endl
<< std::endl << std::endl
<< "Options:" << std::endl << "Options:" << std::endl
<< " -8 output in UTF-8" << std::endl
<< " -d dump priorities, do not generate any formula" << " -d dump priorities, do not generate any formula"
<< std::endl << std::endl
<< " -f N the size of the formula [15]" << std::endl << " -f N the size of the formula [15]" << std::endl
...@@ -89,6 +91,7 @@ main(int argc, char** argv) ...@@ -89,6 +91,7 @@ main(int argc, char** argv)
{ {
enum { OutputBool, OutputLTL, OutputSERE, OutputPSL } output = OutputLTL; enum { OutputBool, OutputLTL, OutputSERE, OutputPSL } output = OutputLTL;
bool opt_d = false; bool opt_d = false;
bool utf8 = false;
int opt_s = 0; int opt_s = 0;
int opt_f = 15; int opt_f = 15;
int opt_F = 1; int opt_F = 1;
...@@ -110,7 +113,11 @@ main(int argc, char** argv) ...@@ -110,7 +113,11 @@ main(int argc, char** argv)
while (++argn < argc) while (++argn < argc)
{ {
if (!strcmp(argv[argn], "-B")) if (!strcmp(argv[argn], "-8"))
{
utf8 = true;
}
else if (!strcmp(argv[argn], "-B"))
{ {
output = OutputBool; output = OutputBool;
} }
...@@ -341,8 +348,9 @@ main(int argc, char** argv) ...@@ -341,8 +348,9 @@ main(int argc, char** argv)
<< "of size " << opt_r << " or more." << std::endl; << "of size " << opt_r << " or more." << std::endl;
exit(2); exit(2);
} }
std::string txt = spot::ltl::to_string(f, false, std::string txt = utf8
output == OutputSERE); ? spot::ltl::to_utf8_string(f, false, output == OutputSERE)
: spot::ltl::to_string(f, false, output == OutputSERE);
f->destroy(); f->destroy();
if (!opt_u || unique.insert(txt).second) if (!opt_u || unique.insert(txt).second)
{ {
......
...@@ -70,3 +70,7 @@ ignoring trailing garbage ...@@ -70,3 +70,7 @@ ignoring trailing garbage
EOF EOF
cmp exp err cmp exp err
../randltl -P -8 -u -s 0 -f 16 a b c -F 100 > formulae
../reduc -f -h 0 formulae
\ No newline at end of file
// -*- coding: utf-8 -*-
// Copyright (C) 2008, 2010, 2012 Laboratoire de Recherche et // Copyright (C) 2008, 2010, 2012 Laboratoire de Recherche et
// Développement de l'Epita (LRDE) // Développement de l'Epita (LRDE)
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
...@@ -79,12 +80,12 @@ namespace spot ...@@ -79,12 +80,12 @@ namespace spot
" R ", " R ",
" W ", " W ",
" M ", " M ",
" <>-> ", "<>-> ",
" <>=> ", "<>=> ",
" <>+> ", "<>+> ",
" <>=+> ", "<>=+> ",
" []-> ", "[]-> ",
" []=> ", "[]=> ",
"!", "!",
"X", "X",
"F", "F",
...@@ -109,12 +110,12 @@ namespace spot ...@@ -109,12 +110,12 @@ namespace spot
" V ", " V ",
" W ", // not supported " W ", // not supported
" M ", // not supported " M ", // not supported
" <>-> ", // not supported "<>-> ", // not supported
" <>=> ", // not supported "<>=> ", // not supported
" <>+> ", // not supported "<>+> ", // not supported
" <>=+> ", // not supported "<>=+> ", // not supported
" []-> ", // not supported "[]-> ", // not supported
" []=> ", // not supported "[]=> ", // not supported
"!", "!",
"()", "()",
"<>", "<>",
...@@ -128,6 +129,36 @@ namespace spot ...@@ -128,6 +129,36 @@ namespace spot
":", // not supported ":", // not supported
}; };
const char* utf8_kw[] = {
"0",
"1",
"[*0]",
"⊕",
" → ",
" ↔ ",
" U ",
" R ",
" W ",
" M ",
"◇→ ",
"◇⇒ ",
"◇→̃ ",
"◇⇒̃ ",
"□→ ",
"□⇒ ",
"¬",
"○",
"◇",
"□",
"∨",
" | ",
"∧",
" ∩ ",
" & ",
";",
":",
};
static bool static bool
is_bare_word(const char* str) is_bare_word(const char* str)
{ {
...@@ -491,7 +522,8 @@ namespace spot ...@@ -491,7 +522,8 @@ namespace spot
top_level_ = true; top_level_ = true;
break; break;
case unop::NegClosure: case unop::NegClosure:
os_ << "!{"; emit(KNot);
os_ << "{";
in_ratexp_ = true; in_ratexp_ = true;
top_level_ = true; top_level_ = true;
break; break;
...@@ -684,6 +716,23 @@ namespace spot ...@@ -684,6 +716,23 @@ namespace spot
return os.str(); return os.str();
} }
std::ostream&
to_utf8_string(const formula* f, std::ostream& os, bool full_parent,
bool ratexp)
{
to_string_visitor v(os, full_parent, ratexp, utf8_kw);
f->accept(v);
return os;
}
std::string
to_utf8_string(const formula* f, bool full_parent, bool ratexp)
{
std::ostringstream os;
to_utf8_string(f, os, full_parent, ratexp);
return os.str();
}
std::ostream& std::ostream&
to_spin_string(const formula* f, std::ostream& os, bool full_parent) to_spin_string(const formula* f, std::ostream& os, bool full_parent)
{ {
......
// Copyright (C) 2010, 2011 Laboratoire de Recherche et Développement de // -*- coding: utf-8 -*-
// l'Epita (LRDE). // Copyright (C) 2010, 2011, 2012 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie. // et Marie Curie.
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
...@@ -54,6 +55,27 @@ namespace spot ...@@ -54,6 +55,27 @@ namespace spot
std::string std::string
to_string(const formula* f, bool full_parent = false, bool ratexp = false); to_string(const formula* f, bool full_parent = false, bool ratexp = false);
/// \brief Output a formula as an utf8 string which is parsable unless
/// the formula contains automaton operators (used in ELTL formulae).
/// \param f The formula to translate.
/// \param os The stream where it should be output.
/// \param full_parent Whether or not the string should by fully
/// parenthesized.
/// \param ratexp Whether we are printing a SERE.
std::ostream&
to_utf8_string(const formula* f, std::ostream& os, bool full_parent = false,
bool ratexp = false);
/// \brief Output a formula as an utf8 string which is parsable
/// unless the formula contains automaton operators (used in ELTL formulae).
/// \param f The formula to translate.
/// \param full_parent Whether or not the string should by fully
/// parenthesized.
/// \param ratexp Whether we are printing a SERE.
std::string
to_utf8_string(const formula* f, bool full_parent = false,
bool ratexp = false);
/// \brief Output a formula as a (parsable by Spin) string. /// \brief Output a formula as a (parsable by Spin) string.
/// \param f The formula to translate. /// \param f The formula to translate.
/// \param os The stream where it should be output. /// \param os The stream where it should be output.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment