python: add a spot.automata(filename) interface, yielding automata

* src/hoaparse/fmterror.cc, src/hoaparse/public.hh,
src/hoaparse/hoaparse.yy (hoa_stream_parser::parse_strict): New method
that raises an exception whenever a syntax error is encountered.
* src/ltlparse/public.hh (parse_error): Move ...
* src/misc/common.hh: ... here.
* wrap/python/spot_impl.i: Wrap the hoa output.
* wrap/python/spot.py: Implement spot.automata.
* wrap/python/tests/automata-io.ipynb: New test.
* wrap/python/tests/Makefile.am: Add it.
This commit is contained in:
Alexandre Duret-Lutz 2015-03-27 10:04:36 +01:00
parent 8e6b35e5e3
commit 25de479e12
9 changed files with 701 additions and 22 deletions

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -24,8 +24,8 @@ namespace spot
{
bool
format_hoa_parse_errors(std::ostream& os,
const std::string& filename,
hoa_parse_error_list& error_list)
const std::string& filename,
hoa_parse_error_list& error_list)
{
bool printed = false;
spot::hoa_parse_error_list::iterator it;

View file

@ -1612,7 +1612,9 @@ static void fix_properties(result_& r)
namespace spot
{
hoa_stream_parser::hoa_stream_parser(const std::string& name)
hoa_stream_parser::hoa_stream_parser(const std::string& name,
bool ignore_abort)
: filename_(name), ignore_abort_(ignore_abort)
{
if (hoayyopen(name))
throw std::runtime_error(std::string("Cannot open file ") + name);
@ -1630,6 +1632,7 @@ namespace spot
ltl::environment& env,
bool debug)
{
restart:
result_ r;
r.h = std::make_shared<spot::hoa_aut>();
r.h->aut = make_tgba_digraph(dict);
@ -1652,7 +1655,11 @@ namespace spot
last_loc = r.h->loc;
last_loc.step();
if (r.h->aborted)
return r.h;
{
if (ignore_abort_)
goto restart;
return r.h;
}
if (!r.h->aut)
return nullptr;
if (r.state_names)
@ -1662,6 +1669,29 @@ namespace spot
fix_properties(r);
return r.h;
};
tgba_digraph_ptr
hoa_stream_parser::parse_strict(const bdd_dict_ptr& dict,
ltl::environment& env,
bool debug)
{
hoa_parse_error_list pel;
auto a = parse(pel, dict, env, debug);
if (!pel.empty())
{
std::ostringstream s;
if (format_hoa_parse_errors(s, filename_, pel))
throw parse_error(s.str());
}
if (!a)
return nullptr;
if (a->aborted)
throw parse_error("parsing aborted");
return a->aut;
}
}
// Local Variables:

View file

@ -60,14 +60,21 @@ namespace spot
class SPOT_API hoa_stream_parser
{
spot::location last_loc;
std::string filename_;
bool ignore_abort_;
public:
hoa_stream_parser(const std::string& filename);
hoa_stream_parser(const std::string& filename, bool ignore_abort = false);
~hoa_stream_parser();
hoa_aut_ptr parse(hoa_parse_error_list& error_list,
const bdd_dict_ptr& dict,
ltl::environment& env =
ltl::default_environment::instance(),
bool debug = false);
// Raises a parse_error on any syntax error
tgba_digraph_ptr parse_strict(const bdd_dict_ptr& dict,
ltl::environment& env =
ltl::default_environment::instance(),
bool debug = false);
};
/// \brief Build a spot::tgba_digraph from a HOA file or a neverclaim.