summaryrefslogtreecommitdiff
path: root/src/parser.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-03 14:42:46 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-03 14:42:46 -0400
commit67a45a0e3cdb92ead1214740281f6f39407ad846 (patch)
treeff86d22de29f1cbbb3f48864817d5614472618b3 /src/parser.cc
parentba9efa3ab906b4fd21f1e982baaa3e6e0019115b (diff)
downloadfork-ledger-67a45a0e3cdb92ead1214740281f6f39407ad846.tar.gz
fork-ledger-67a45a0e3cdb92ead1214740281f6f39407ad846.tar.bz2
fork-ledger-67a45a0e3cdb92ead1214740281f6f39407ad846.zip
Made error reporting while parsing more resilient
Diffstat (limited to 'src/parser.cc')
-rw-r--r--src/parser.cc12
1 files changed, 6 insertions, 6 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;
}