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

* 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.
parent 7425f4a9
2003-04-16 Alexandre DURET-LUTZ <aduret@circe.lip6.fr> 2003-04-16 Alexandre DURET-LUTZ <aduret@circe.lip6.fr>
* 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.
* src/ltlvisit/equals.cc, src/ltlvisit/equals.hh: New files. * src/ltlvisit/equals.cc, src/ltlvisit/equals.hh: New files.
* src/ltlvisit/Makefile.am (libltlvisit_a_SOURCES): Add equals.hh * src/ltlvisit/Makefile.am (libltlvisit_a_SOURCES): Add equals.hh
and equals.cc. and equals.cc.
......
...@@ -21,6 +21,7 @@ $(FROM_LTLPARSE_YY_OTHERS): $(LTLPARSE_YY) ...@@ -21,6 +21,7 @@ $(FROM_LTLPARSE_YY_OTHERS): $(LTLPARSE_YY)
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(FROM_LTLPARSE_YY_MAIN) @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(FROM_LTLPARSE_YY_MAIN)
libltlparse_a_SOURCES = \ libltlparse_a_SOURCES = \
fmterror.cc \
$(FROM_LTLPARSE_YY) \ $(FROM_LTLPARSE_YY) \
ltlscan.ll \ ltlscan.ll \
parsedecl.hh \ parsedecl.hh \
......
#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;
}
}
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# include "location.hh" # include "location.hh"
# include <list> # include <list>
# include <utility> # include <utility>
# include <iostream>
namespace spot namespace spot
{ {
...@@ -18,6 +19,11 @@ namespace spot ...@@ -18,6 +19,11 @@ namespace spot
formulae* parse(const std::string& ltl_string, formulae* parse(const std::string& ltl_string,
parse_error_list& error_list, parse_error_list& error_list,
bool debug = false); 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);
} }
} }
......
...@@ -9,30 +9,6 @@ syntax(char *prog) ...@@ -9,30 +9,6 @@ syntax(char *prog)
exit(2); exit(2);
} }
bool
print_parse_error(const char* f, spot::ltl::parse_error_list& pel)
{
bool err = false;
spot::ltl::parse_error_list::iterator it;
for (it = pel.begin(); it != pel.end(); ++it)
{
std::cerr << ">>> " << f << std::endl;
unsigned n = 0;
yy::Location& l = it->first;
for (; n < 4 + l.begin.column; ++n)
std::cerr << ' ';
// Write at least one '^', even if begin==end.
std::cerr << '^';
++n;
for (; n < 4 + l.end.column; ++n)
std::cerr << '^';
std::cerr << std::endl << it->second << std::endl << std::endl;
err = true;
}
return err;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
...@@ -43,13 +19,13 @@ main(int argc, char **argv) ...@@ -43,13 +19,13 @@ main(int argc, char **argv)
spot::ltl::parse_error_list p1; spot::ltl::parse_error_list p1;
spot::ltl::formulae *f1 = spot::ltl::parse(argv[1], p1); spot::ltl::formulae *f1 = spot::ltl::parse(argv[1], p1);
if (print_parse_error(argv[1], p1)) if (spot::ltl::format_parse_errors(std::cerr, argv[1], p1))
return 2; return 2;
spot::ltl::parse_error_list p2; spot::ltl::parse_error_list p2;
spot::ltl::formulae *f2 = spot::ltl::parse(argv[2], p2); spot::ltl::formulae *f2 = spot::ltl::parse(argv[2], p2);
if (print_parse_error(argv[2], p2)) if (spot::ltl::format_parse_errors(std::cerr, argv[2], p2))
return 2; return 2;
if (equals(f1, f2)) if (equals(f1, f2))
......
...@@ -34,21 +34,8 @@ main(int argc, char **argv) ...@@ -34,21 +34,8 @@ main(int argc, char **argv)
pel, debug); pel, debug);
spot::ltl::parse_error_list::iterator it; spot::ltl::parse_error_list::iterator it;
for (it = pel.begin(); it != pel.end(); ++it) exit_code =
{ spot::ltl::format_parse_errors(std::cerr, argv[formulae_index], pel);
std::cerr << ">>> " << argv[formulae_index] << std::endl;
unsigned n = 0;
yy::Location& l = it->first;
for (; n < 4 + l.begin.column; ++n)
std::cerr << ' ';
// Write at least one '^', even if begin==end.
std::cerr << '^';
++n;
for (; n < 4 + l.end.column; ++n)
std::cerr << '^';
std::cerr << std::endl << it->second << std::endl << std::endl;
exit_code = 1;
}
if (f) if (f)
{ {
......
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