parseaut: allow false edges to not be dropped

This is a followup to issue #548, which was caused by edges being
dropped.  In that context dropping edge was not really desirable, so
let's make this behavior configurable.

* spot/parseaut/public.hh: Add a new option.
* python/spot/__init__.py: Likewise.
* spot/parseaut/parseaut.yy: Honor that option.
* tests/python/parsetgba.py: Add a short test for it.
* NEWS: Mention it.
This commit is contained in:
Alexandre Duret-Lutz 2023-11-14 22:21:52 +01:00
parent bed87c60a4
commit 35fca49075
5 changed files with 84 additions and 19 deletions

View file

@ -1649,7 +1649,7 @@ incorrectly-unlabeled-edge: checked-state-num trans-acc_opt
"(previous edge is labeled)");
else
cond = res.state_label;
if (cond != bddfalse)
if (cond != bddfalse || !res.opts.drop_false_edges)
{
unsigned e;
if (res.opts.want_kripke)
@ -1665,12 +1665,13 @@ incorrectly-unlabeled-edge: checked-state-num trans-acc_opt
labeled-edge: trans-label checked-state-num trans-acc_opt
{
unsigned e = 0;
if (res.cur_label != bddfalse ||
if (res.cur_label != bddfalse
|| !res.opts.drop_false_edges
// As a hack to allow states to be accepting
// even if they do not have transitions, we
// do not ignore false-labeled self-loops if they
// have some colors)
($2 == res.cur_state && !!($3 | res.acc_state)))
|| ($2 == res.cur_state && !!($3 | res.acc_state)))
{
if (res.opts.want_kripke)
e = res.h->ks->new_edge(res.cur_state, $2);
@ -1684,7 +1685,7 @@ labeled-edge: trans-label checked-state-num trans-acc_opt
| trans-label state-conj-checked trans-acc_opt
{
unsigned e = 0;
if (res.cur_label != bddfalse)
if (res.cur_label != bddfalse || !res.opts.drop_false_edges)
{
assert(!res.opts.want_kripke);
e = res.h->aut->new_univ_edge(res.cur_state,
@ -1737,7 +1738,7 @@ unlabeled-edge: checked-state-num trans-acc_opt
}
}
unsigned e = 0;
if (cond != bddfalse)
if (cond != bddfalse || !res.opts.drop_false_edges)
{
if (res.opts.want_kripke)
e = res.h->ks->new_edge(res.cur_state, $1);
@ -1770,7 +1771,7 @@ unlabeled-edge: checked-state-num trans-acc_opt
}
}
unsigned e = 0;
if (cond != bddfalse)
if (cond != bddfalse || !res.opts.drop_false_edges)
{
assert(!res.opts.want_kripke);
e = res.h->aut->new_univ_edge(res.cur_state,

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014, 2015, 2016, 2017, 2022 Laboratoire de Recherche et
// Copyright (C) 2013-2017, 2022-2023 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -103,6 +103,7 @@ namespace spot
bool trust_hoa = true; ///< Trust properties in HOA files
bool raise_errors = false; ///< Raise errors as exceptions.
bool want_kripke = false; ///< Parse as a Kripke structure.
bool drop_false_edges = true; ///< Drop edges with false labels.
};
/// \brief Parse a stream of automata
@ -193,12 +194,12 @@ namespace spot
/// \param opts Additional options to pass to the parser.
/// \return A pointer to a \c parsed_aut structure.
///
/// This is a wrapper around spot::automaton_stream_parser that returns
/// the first automaton of the file. Empty inputs are reported as
/// syntax errors, so the \c aut field of the result is guaranteed not
/// to be null if \c errors is empty. (This is unlike
/// automaton_stream_parser::parse() where a null \c aut denots the
/// end of a stream.)
/// This is a wrapper around spot::automaton_stream_parser that
/// returns the first automaton of the file. Empty inputs are
/// reported as syntax errors, so the \c aut field of the result is
/// guaranteed not to be null if \c errors is empty. (This is
/// unlike automaton_stream_parser::parse() where a null \c aut
/// denotes the end of a stream.)
///
/// \warning This function is not reentrant.
SPOT_API parsed_aut_ptr