* src/ltlparse/public.hh (format_parse_errors): New function.

* src/ltlparse/fmterror.cc: New file.
* src/ltlparse/Makefile.am (libltlparse_a_SOURCES): Add fmterror.cc.
* src/ltltests/equals.cc, src/ltltests/readltl.cc: Simplify using
format_parse_errors.
This commit is contained in:
Alexandre Duret-Lutz 2003-04-16 12:58:17 +00:00
parent 7425f4a91e
commit 532f9131f5
6 changed files with 52 additions and 41 deletions

View file

@ -21,6 +21,7 @@ $(FROM_LTLPARSE_YY_OTHERS): $(LTLPARSE_YY)
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(FROM_LTLPARSE_YY_MAIN)
libltlparse_a_SOURCES = \
fmterror.cc \
$(FROM_LTLPARSE_YY) \
ltlscan.ll \
parsedecl.hh \

35
src/ltlparse/fmterror.cc Normal file
View file

@ -0,0 +1,35 @@
#include "public.hh"
namespace spot
{
namespace ltl
{
bool
format_parse_errors(std::ostream& os,
const std::string& ltl_string,
parse_error_list& error_list)
{
bool printed = false;
spot::ltl::parse_error_list::iterator it;
for (it = error_list.begin(); it != error_list.end(); ++it)
{
os << ">>> " << ltl_string << std::endl;
yy::Location& l = it->first;
unsigned n = 0;
for (; n < 4 + l.begin.column; ++n)
os << ' ';
// Write at least one '^', even if begin==end.
os << '^';
++n;
for (; n < 4 + l.end.column; ++n)
os << '^';
os << std::endl << it->second << std::endl << std::endl;
printed = true;
}
return printed;
}
}
}

View file

@ -6,6 +6,7 @@
# include "location.hh"
# include <list>
# include <utility>
# include <iostream>
namespace spot
{
@ -18,6 +19,11 @@ namespace spot
formulae* parse(const std::string& ltl_string,
parse_error_list& error_list,
bool debug = false);
// Return true iff any diagnostic was output to os.
bool format_parse_errors(std::ostream& os,
const std::string& ltl_string,
parse_error_list& error_list);
}
}