diff options
-rw-r--r-- | src/parser.cc | 12 | ||||
-rw-r--r-- | src/token.cc | 2 |
2 files changed, 7 insertions, 7 deletions
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<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", " 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<std::size_t>(pos), - static_cast<std::size_t>(end_pos))); + add_error_context(line_context(*original_string, pos, end_pos)); } throw; } diff --git a/src/token.cc b/src/token.cc index 0a8fce7e..11fda7d7 100644 --- a/src/token.cc +++ b/src/token.cc @@ -451,7 +451,7 @@ void expr_t::token_t::unexpected() case VALUE: throw_(parse_error, _("Unexpected value '%1'") << value); default: - throw_(parse_error, _("Unexpected operator '%1'") << symbol); + throw_(parse_error, _("Unexpected token '%1'") << symbol); } } |