Made error reporting while parsing more resilient

This commit is contained in:
John Wiegley 2009-03-03 14:42:46 -04:00
parent ba9efa3ab9
commit 67a45a0e3c
2 changed files with 7 additions and 7 deletions

View file

@ -477,10 +477,12 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags,
if (original_string) { if (original_string) {
add_error_context(_("While parsing value expression:")); add_error_context(_("While parsing value expression:"));
istream_pos_type end_pos = in.tellg(); std::size_t end_pos =
istream_pos_type pos = end_pos; in.good() ? static_cast<std::size_t>(in.tellg()) : 0;
std::size_t pos = static_cast<std::size_t>(end_pos);
pos -= lookahead.length; if (pos > 0)
pos -= lookahead.length;
DEBUG("parser.error", "original_string = '" << *original_string << "'"); DEBUG("parser.error", "original_string = '" << *original_string << "'");
DEBUG("parser.error", " pos = " << pos); 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 kind = " << int(lookahead.kind));
DEBUG("parser.error", " token length = " << lookahead.length); DEBUG("parser.error", " token length = " << lookahead.length);
add_error_context(line_context(*original_string, add_error_context(line_context(*original_string, pos, end_pos));
static_cast<std::size_t>(pos),
static_cast<std::size_t>(end_pos)));
} }
throw; throw;
} }

View file

@ -451,7 +451,7 @@ void expr_t::token_t::unexpected()
case VALUE: case VALUE:
throw_(parse_error, _("Unexpected value '%1'") << value); throw_(parse_error, _("Unexpected value '%1'") << value);
default: default:
throw_(parse_error, _("Unexpected operator '%1'") << symbol); throw_(parse_error, _("Unexpected token '%1'") << symbol);
} }
} }