From 812d38c176b76b0fda5228338f5c5d70b3c6edf1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 22 Jan 2009 21:16:43 -0400 Subject: Correctly report the line context when there is a valexpr parsing error. --- src/parser.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/parser.cc') diff --git a/src/parser.cc b/src/parser.cc index 82bc771d..4881f7bc 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -399,11 +399,21 @@ expr_t::parser_t::parse(std::istream& in, const flags_t flags, return top_node; } catch (const std::exception& err) { - add_error_context("While parsing value expression:"); if (original_string) { - istream_pos_type pos = in.tellg(); - pos -= 1; - add_error_context(line_context(*original_string, pos)); + add_error_context("While parsing value expression:"); + + istream_pos_type end_pos = in.tellg(); + istream_pos_type pos = end_pos; + + pos -= lookahead.length; + + DEBUG("parser.error", "original_string = '" << *original_string << "'"); + DEBUG("parser.error", " pos = " << pos); + DEBUG("parser.error", " end_pos = " << end_pos); + DEBUG("parser.error", " token kind = " << int(lookahead.kind)); + DEBUG("parser.error", " token length = " << lookahead.length); + + add_error_context(line_context(*original_string, pos, end_pos)); } throw; } -- cgit v1.2.3