parsetl: change the interface to return a parsed_formula
This gets the interface of all the functions parsing formula in line with the interface of the automaton parser: both return a "parsed_*" object (parsed_formula or parsed_automaton) that contains the said object and its list of errors. Doing so avoid having to declare the parse_error_list in advance. * spot/tl/parse.hh, spot/parsetl/parsetl.yy: Do the change. * spot/parsetl/fmterror.cc: Adjust the error printer. * NEWS: Document it. * bin/common_finput.cc, bin/common_finput.hh, bin/ltlcross.cc, bin/ltldo.cc, bin/ltlfilt.cc, doc/org/tut01.org, doc/org/tut02.org, doc/org/tut10.org, doc/org/tut20.org, python/ajax/spotcgi.in, python/spot/impl.i, spot/parseaut/parseaut.yy, tests/core/checkpsl.cc, tests/core/checkta.cc, tests/core/consterm.cc, tests/core/emptchk.cc, tests/core/equalsf.cc, tests/core/ikwiad.cc, tests/core/kind.cc, tests/core/length.cc, tests/core/ltlprod.cc, tests/core/ltlrel.cc, tests/core/randtgba.cc, tests/core/readltl.cc, tests/core/reduc.cc, tests/core/safra.cc, tests/core/syntimpl.cc, tests/core/tostring.cc, tests/ltsmin/modelcheck.cc, tests/python/alarm.py, tests/python/interdep.py, tests/python/ltl2tgba.py, tests/python/ltlparse.py: Adjust all uses.
This commit is contained in:
parent
cf4f58c34b
commit
22f442f758
37 changed files with 359 additions and 374 deletions
|
|
@ -72,11 +72,10 @@ namespace spot
|
|||
const parse_error_list& error_list)
|
||||
{
|
||||
bool printed = false;
|
||||
parse_error_list::const_iterator it;
|
||||
for (it = error_list.begin(); it != error_list.end(); ++it)
|
||||
for (auto it: error_list)
|
||||
{
|
||||
os << ">>> " << ltl_string << std::endl;
|
||||
const location& l = it->first;
|
||||
os << ">>> " << ltl_string << '\n';
|
||||
const location& l = it.first;
|
||||
|
||||
unsigned n = 1;
|
||||
for (; n < 4 + l.begin.column; ++n)
|
||||
|
|
@ -86,7 +85,7 @@ namespace spot
|
|||
++n;
|
||||
for (; n < 4 + l.end.column; ++n)
|
||||
os << '^';
|
||||
os << std::endl << it->second << std::endl << std::endl;
|
||||
os << '\n' << it.second << "\n\n";
|
||||
printed = true;
|
||||
}
|
||||
return printed;
|
||||
|
|
@ -94,19 +93,17 @@ namespace spot
|
|||
}
|
||||
|
||||
bool
|
||||
format_parse_errors(std::ostream& os,
|
||||
const std::string& ltl_string,
|
||||
const parse_error_list& error_list)
|
||||
parsed_formula::format_errors(std::ostream& os)
|
||||
{
|
||||
if (utf8::is_valid(ltl_string.begin(), ltl_string.end()))
|
||||
if (utf8::is_valid(input.begin(), input.end()))
|
||||
{
|
||||
parse_error_list fixed = error_list;
|
||||
fix_utf8_locations(ltl_string, fixed);
|
||||
return format_parse_errors_aux(os, ltl_string, fixed);
|
||||
parse_error_list fixed = errors;
|
||||
fix_utf8_locations(input, fixed);
|
||||
return format_parse_errors_aux(os, input, fixed);
|
||||
}
|
||||
else
|
||||
{
|
||||
return format_parse_errors_aux(os, ltl_string, error_list);
|
||||
return format_parse_errors_aux(os, input, errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* -*- coding: utf-8 -*-
|
||||
** Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Laboratoire
|
||||
** Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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),
|
||||
|
|
@ -120,25 +120,24 @@ using namespace spot;
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
spot::parse_error_list suberror;
|
||||
formula f;
|
||||
spot::parsed_formula pf;
|
||||
switch (type)
|
||||
{
|
||||
case parser_sere:
|
||||
f = spot::parse_infix_sere(str, suberror, env, debug, true);
|
||||
pf = spot::parse_infix_sere(str, env, debug, true);
|
||||
break;
|
||||
case parser_bool:
|
||||
f = spot::parse_infix_boolean(str, suberror, env, debug, true);
|
||||
pf = spot::parse_infix_boolean(str, env, debug, true);
|
||||
break;
|
||||
case parser_ltl:
|
||||
f = spot::parse_infix_psl(str, suberror, env, debug, true);
|
||||
pf = spot::parse_infix_psl(str, env, debug, true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (suberror.empty())
|
||||
return f;
|
||||
if (pf.errors.empty())
|
||||
return pf.f;
|
||||
|
||||
f = env.require(str);
|
||||
auto f = env.require(str);
|
||||
if (!f)
|
||||
{
|
||||
std::string s = "atomic proposition `";
|
||||
|
|
@ -993,69 +992,65 @@ tlyy::parser::error(const location_type& location, const std::string& message)
|
|||
|
||||
namespace spot
|
||||
{
|
||||
formula
|
||||
parsed_formula
|
||||
parse_infix_psl(const std::string& ltl_string,
|
||||
parse_error_list& error_list,
|
||||
environment& env,
|
||||
bool debug, bool lenient)
|
||||
{
|
||||
formula result = nullptr;
|
||||
parsed_formula result(ltl_string);
|
||||
flex_set_buffer(ltl_string,
|
||||
tlyy::parser::token::START_LTL,
|
||||
lenient);
|
||||
tlyy::parser parser(error_list, env, result);
|
||||
tlyy::parser parser(result.errors, env, result.f);
|
||||
parser.set_debug_level(debug);
|
||||
parser.parse();
|
||||
flex_unset_buffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
formula
|
||||
parsed_formula
|
||||
parse_infix_boolean(const std::string& ltl_string,
|
||||
parse_error_list& error_list,
|
||||
environment& env,
|
||||
bool debug, bool lenient)
|
||||
{
|
||||
formula result = nullptr;
|
||||
parsed_formula result(ltl_string);
|
||||
flex_set_buffer(ltl_string,
|
||||
tlyy::parser::token::START_BOOL,
|
||||
lenient);
|
||||
tlyy::parser parser(error_list, env, result);
|
||||
tlyy::parser parser(result.errors, env, result.f);
|
||||
parser.set_debug_level(debug);
|
||||
parser.parse();
|
||||
flex_unset_buffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
formula
|
||||
parsed_formula
|
||||
parse_prefix_ltl(const std::string& ltl_string,
|
||||
parse_error_list& error_list,
|
||||
environment& env,
|
||||
bool debug)
|
||||
{
|
||||
formula result = nullptr;
|
||||
parsed_formula result(ltl_string);
|
||||
flex_set_buffer(ltl_string,
|
||||
tlyy::parser::token::START_LBT,
|
||||
false);
|
||||
tlyy::parser parser(error_list, env, result);
|
||||
tlyy::parser parser(result.errors, env, result.f);
|
||||
parser.set_debug_level(debug);
|
||||
parser.parse();
|
||||
flex_unset_buffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
formula
|
||||
parsed_formula
|
||||
parse_infix_sere(const std::string& sere_string,
|
||||
parse_error_list& error_list,
|
||||
environment& env,
|
||||
bool debug,
|
||||
bool lenient)
|
||||
{
|
||||
formula result = nullptr;
|
||||
parsed_formula result(sere_string);
|
||||
flex_set_buffer(sere_string,
|
||||
tlyy::parser::token::START_SERE,
|
||||
lenient);
|
||||
tlyy::parser parser(error_list, env, result);
|
||||
tlyy::parser parser(result.errors, env, result.f);
|
||||
parser.set_debug_level(debug);
|
||||
parser.parse();
|
||||
flex_unset_buffer();
|
||||
|
|
@ -1065,19 +1060,17 @@ namespace spot
|
|||
formula
|
||||
parse_formula(const std::string& ltl_string, environment& env)
|
||||
{
|
||||
parse_error_list pel;
|
||||
formula f = parse_infix_psl(ltl_string, pel, env);
|
||||
parsed_formula pf = parse_infix_psl(ltl_string, env);
|
||||
std::ostringstream s;
|
||||
if (format_parse_errors(s, ltl_string, pel))
|
||||
if (pf.format_errors(s))
|
||||
{
|
||||
parse_error_list pel2;
|
||||
formula g = parse_prefix_ltl(ltl_string, pel2, env);
|
||||
if (pel2.empty())
|
||||
return g;
|
||||
parsed_formula pg = parse_prefix_ltl(ltl_string, env);
|
||||
if (pg.errors.empty())
|
||||
return pg.f;
|
||||
else
|
||||
throw parse_error(s.str());
|
||||
}
|
||||
return f;
|
||||
return pf.f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue