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

hoa: add support for --ABORT--

* src/hoaparse/parsedecl.hh (hoa_abort): New structure.
* src/hoaparse/hoascan.ll: Throw hoa_abort on --ABORT--.
* src/hoaparse/hoaparse.yy: Deal with this exception.
* src/hoaparse/public.hh: Add a boolean flag to mark aborted automata.
* src/bin/autfilt.cc: Report aborted automata.
* src/tgbatest/hoaparse.test: Add test case.
parent 8c8c2f0b
...@@ -331,6 +331,12 @@ namespace ...@@ -331,6 +331,12 @@ namespace
return 0; return 0;
} }
int
aborted(const spot::const_hoa_aut_ptr& h, const char* filename)
{
std::cerr << filename << ':' << h->loc << ": aborted input automaton\n";
return 2;
}
int int
process_file(const char* filename) process_file(const char* filename)
...@@ -351,6 +357,8 @@ namespace ...@@ -351,6 +357,8 @@ namespace
err = 2; err = 2;
if (!haut) if (!haut)
error(2, 0, "failed to read automaton from %s", filename); error(2, 0, "failed to read automaton from %s", filename);
else if (haut->aborted)
err = std::max(err, aborted(haut, filename));
else else
process_automaton(haut, filename); process_automaton(haut, filename);
} }
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
spot::location state_label_loc; spot::location state_label_loc;
spot::location start_loc; spot::location start_loc;
spot::location accset_loc; spot::location accset_loc;
spot::location last_loc;
spot::acc_cond::mark_t acc_state; spot::acc_cond::mark_t acc_state;
spot::acc_cond::mark_t neg_acc_sets = 0U; spot::acc_cond::mark_t neg_acc_sets = 0U;
spot::acc_cond::mark_t pos_acc_sets = 0U; spot::acc_cond::mark_t pos_acc_sets = 0U;
...@@ -81,7 +80,7 @@ ...@@ -81,7 +80,7 @@
%parse-param {result_& res} %parse-param {result_& res}
%parse-param {spot::location initial_loc} %parse-param {spot::location initial_loc}
%initial-action { @$ = initial_loc; } %initial-action { @$ = res.h->loc = initial_loc; }
%union %union
{ {
...@@ -142,7 +141,7 @@ ...@@ -142,7 +141,7 @@
%% %%
hoa: header "--BODY--" body "--END--" hoa: header "--BODY--" body "--END--"
{ {
res.last_loc = @$; res.h->loc = @$;
YYACCEPT; YYACCEPT;
} }
hoa: ENDOFFILE { YYABORT; } hoa: ENDOFFILE { YYABORT; }
...@@ -174,11 +173,11 @@ header: format-version header-items ...@@ -174,11 +173,11 @@ header: format-version header-items
} }
} }
format-version: "HOA:" IDENTIFIER format-version: "HOA:" { res.h->loc = @1; } IDENTIFIER
{ {
if (*$2 != "v1") if (*$3 != "v1")
error(@$, "unsupported version of the HOA format"); error(@$, "unsupported version of the HOA format");
delete $2; delete $3;
} }
header-items: | header-items header-item header-items: | header-items header-item
...@@ -685,9 +684,21 @@ namespace spot ...@@ -685,9 +684,21 @@ namespace spot
r.env = &env; r.env = &env;
hoayy::parser parser(error_list, r, last_loc); hoayy::parser parser(error_list, r, last_loc);
parser.set_debug_level(debug); parser.set_debug_level(debug);
if (parser.parse()) try
r.h->aut = nullptr; {
last_loc = r.last_loc; if (parser.parse())
r.h->aut = nullptr;
}
catch (const spot::hoa_abort& e)
{
r.h->aborted = true;
// Bison 3.0.2 lacks a += operator for locations.
r.h->loc = r.h->loc + e.pos;
}
last_loc = r.h->loc;
last_loc.step();
if (r.h->aborted)
return r.h;
if (!r.h->aut) if (!r.h->aut)
return nullptr; return nullptr;
if (r.neg_acc_sets) if (r.neg_acc_sets)
......
...@@ -65,6 +65,7 @@ identifier [[:alpha:]_][[:alnum:]_-]* ...@@ -65,6 +65,7 @@ identifier [[:alpha:]_][[:alnum:]_-]*
"name:" return token::NAME; "name:" return token::NAME;
"properties:" return token::PROPERTIES; "properties:" return token::PROPERTIES;
"--BODY--" return token::BODY; "--BODY--" return token::BODY;
"--ABORT--" throw spot::hoa_abort{*yylloc};
"--END--" return token::END; "--END--" return token::END;
"State:" return token::STATE; "State:" return token::STATE;
[tf{}()\[\]&|!] return *yytext; [tf{}()\[\]&|!] return *yytext;
......
...@@ -34,6 +34,12 @@ namespace spot ...@@ -34,6 +34,12 @@ namespace spot
{ {
int hoayyopen(const std::string& name); int hoayyopen(const std::string& name);
void hoayyclose(); void hoayyclose();
// This exception is thrown by the lexer when it reads "--ABORT--".
struct hoa_abort
{
spot::location pos;
};
} }
#endif // SPOT_HOAPARSE_PARSEDECL_HH #endif // SPOT_HOAPARSE_PARSEDECL_HH
...@@ -46,6 +46,8 @@ namespace spot ...@@ -46,6 +46,8 @@ namespace spot
// Transition structure of the automaton. // Transition structure of the automaton.
// This is encoded as a TGBA without acceptance condition. // This is encoded as a TGBA without acceptance condition.
tgba_digraph_ptr aut; tgba_digraph_ptr aut;
bool aborted = false;
spot::location loc;
}; };
typedef std::shared_ptr<hoa_aut> hoa_aut_ptr; typedef std::shared_ptr<hoa_aut> hoa_aut_ptr;
......
...@@ -26,7 +26,7 @@ set -e ...@@ -26,7 +26,7 @@ set -e
expecterr() expecterr()
{ {
cat >$1.exp cat >$1.exp
../../bin/autfilt $1 2>$1.err && exit 1 ../../bin/autfilt --hoa $1 2>$1.err >$1.out && exit 1
test $? = 2 test $? = 2
cat $1.err cat $1.err
diff $1.err $1.exp diff $1.err $1.exp
...@@ -390,6 +390,22 @@ EOF ...@@ -390,6 +390,22 @@ EOF
cat >input <<EOF cat >input <<EOF
HOA: v1 HOA: v1
--ABORT--
HOA: v1
States: 2
Start: 0
Acceptance: 2 (Inf(0) & Inf(!0)) &
--ABORT----ABORT--
HOA: v1
States: 2
Start: 0
Acceptance: 2 (Inf(0) & Inf(!0)) & Inf(!1)
AP: 1 "a"
--BODY-- State: 0 {0
}
[0] 1
[!0--ABORT--
HOA: v1
States: 2 States: 2
Start: 0 Start: 0
Acceptance: 2 (Inf(0) & Inf(!0)) & Inf(!1) Acceptance: 2 (Inf(0) & Inf(!0)) & Inf(!1)
...@@ -404,7 +420,14 @@ State: 1 ...@@ -404,7 +420,14 @@ State: 1
--END-- --END--
EOF EOF
expectok input <<EOF expecterr input <<EOF
input:1.1-2.9: aborted input automaton
input:3.1-7.14: aborted input automaton
input:7.15-23: aborted input automaton
input:8.1-16.12: aborted input automaton
EOF
cat >expected <<EOF
HOA: v1 HOA: v1
States: 2 States: 2
Start: 0 Start: 0
...@@ -421,3 +444,5 @@ State: 1 ...@@ -421,3 +444,5 @@ State: 1
[0] 0 {1 2} [0] 0 {1 2}
--END-- --END--
EOF EOF
diff expected input.out
Markdown is supported
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