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
|
|
@ -33,6 +33,7 @@
|
|||
%code requires
|
||||
{
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "public.hh"
|
||||
#include "ltlast/allnodes.hh"
|
||||
#include "ltlvisit/tostring.hh"
|
||||
|
|
@ -1034,6 +1035,24 @@ namespace spot
|
|||
return result;
|
||||
}
|
||||
|
||||
const formula*
|
||||
parse_formula(const std::string& ltl_string, environment& env)
|
||||
{
|
||||
parse_error_list pel;
|
||||
const formula* f = parse(ltl_string, pel, env);
|
||||
std::ostringstream s;
|
||||
if (format_parse_errors(s, ltl_string, pel))
|
||||
{
|
||||
parse_error_list pel2;
|
||||
const formula* g = parse_lbt(ltl_string, pel2, env);
|
||||
if (pel2.empty())
|
||||
return g;
|
||||
else
|
||||
throw parse_error(s.str());
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ BOXDARROW {BOX}{DARROWL}|"|"{DARROWL}|"⤇"
|
|||
unput(')');
|
||||
if (!missing_parent)
|
||||
error_list.push_back(
|
||||
spot::ltl::parse_error(*yylloc,
|
||||
spot::ltl::one_parse_error(*yylloc,
|
||||
"missing closing parenthese"));
|
||||
missing_parent = true;
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ BOXDARROW {BOX}{DARROWL}|"|"{DARROWL}|"⤇"
|
|||
unput(')');
|
||||
if (!missing_parent)
|
||||
error_list.push_back(
|
||||
spot::ltl::parse_error(*yylloc,
|
||||
spot::ltl::one_parse_error(*yylloc,
|
||||
"missing closing brace"));
|
||||
missing_parent = true;
|
||||
}
|
||||
|
|
@ -204,7 +204,7 @@ BOXDARROW {BOX}{DARROWL}|"|"{DARROWL}|"⤇"
|
|||
if (errno || yylval->num != n)
|
||||
{
|
||||
error_list.push_back(
|
||||
spot::ltl::parse_error(*yylloc,
|
||||
spot::ltl::one_parse_error(*yylloc,
|
||||
"value too large ignored"));
|
||||
// Skip this number and read next token
|
||||
yylloc->step();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2010, 2011, 2012, 2013 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2010, 2011, 2012, 2013, 2014 Laboratoire de Recherche
|
||||
// et Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique de
|
||||
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
|
||||
// Université Pierre et Marie Curie.
|
||||
|
|
@ -40,9 +40,9 @@ namespace spot
|
|||
|
||||
#ifndef SWIG
|
||||
/// \brief A parse diagnostic with its location.
|
||||
typedef std::pair<location, std::string> parse_error;
|
||||
typedef std::pair<location, std::string> one_parse_error;
|
||||
/// \brief A list of parser diagnostics, as filled by parse.
|
||||
typedef std::list<parse_error> parse_error_list;
|
||||
typedef std::list<one_parse_error> parse_error_list;
|
||||
#else
|
||||
// Turn parse_error_list into an opaque type for Swig.
|
||||
struct parse_error_list {};
|
||||
|
|
@ -124,6 +124,24 @@ namespace spot
|
|||
environment& env = default_environment::instance(),
|
||||
bool debug = false);
|
||||
|
||||
|
||||
|
||||
struct SPOT_API parse_error: public std::runtime_error
|
||||
{
|
||||
parse_error(const std::string& s): std::runtime_error(s)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief A simple wrapper to parse() and parse_lbt().
|
||||
///
|
||||
/// This is mostly meant for interactive use. It first tries parse(); if
|
||||
/// this fails it tries parse_lbt(); and if both fails it returns the errors
|
||||
/// of the first call to parse() as a std::runtime_error().
|
||||
SPOT_API const formula*
|
||||
parse_formula(const std::string& ltl_string,
|
||||
environment& env = default_environment::instance());
|
||||
|
||||
/// \brief Build a formula from a string representing a SERE.
|
||||
/// \param sere_string The string to parse.
|
||||
/// \param error_list A list that will be filled with
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue