From 67a45a0e3cdb92ead1214740281f6f39407ad846 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 3 Mar 2009 14:42:46 -0400 Subject: Made error reporting while parsing more resilient --- src/parser.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/parser.cc') diff --git a/src/parser.cc b/src/parser.cc index b3457f08..c651385f 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -477,10 +477,12 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags, if (original_string) { add_error_context(_("While parsing value expression:")); - istream_pos_type end_pos = in.tellg(); - istream_pos_type pos = end_pos; + std::size_t end_pos = + in.good() ? static_cast(in.tellg()) : 0; + std::size_t pos = static_cast(end_pos); - pos -= lookahead.length; + if (pos > 0) + pos -= lookahead.length; DEBUG("parser.error", "original_string = '" << *original_string << "'"); DEBUG("parser.error", " pos = " << pos); @@ -488,9 +490,7 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags, DEBUG("parser.error", " token kind = " << int(lookahead.kind)); DEBUG("parser.error", " token length = " << lookahead.length); - add_error_context(line_context(*original_string, - static_cast(pos), - static_cast(end_pos))); + add_error_context(line_context(*original_string, pos, end_pos)); } throw; } -- cgit v1.2.3