summaryrefslogtreecommitdiff
path: root/src/textual.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-16 03:50:40 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-03-16 03:50:40 -0500
commit20c076dff92806c6c2aae7c0c87b000ffc703382 (patch)
treea61daca6d4a58ae1f6940c628970ca406c64006b /src/textual.cc
parentdc91d4f1e6fc06ac5c4e50e3ee650844b7a77a2e (diff)
downloadfork-ledger-20c076dff92806c6c2aae7c0c87b000ffc703382.tar.gz
fork-ledger-20c076dff92806c6c2aae7c0c87b000ffc703382.tar.bz2
fork-ledger-20c076dff92806c6c2aae7c0c87b000ffc703382.zip
Improved error reports about leading whitespace
Diffstat (limited to 'src/textual.cc')
-rw-r--r--src/textual.cc17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/textual.cc b/src/textual.cc
index e7c523d9..3555ea4d 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -133,7 +133,7 @@ namespace {
}
#endif
- void read_next_directive();
+ void read_next_directive(bool& error_flag);
#if defined(TIMELOG_SUPPORT)
void clock_in_directive(char * line, bool capitalized);
@@ -251,11 +251,15 @@ void instance_t::parse()
context.linenum = 0;
context.curr_pos = in.tellg();
+ bool error_flag = false;
+
while (in.good() && ! in.eof()) {
try {
- read_next_directive();
+ read_next_directive(error_flag);
}
catch (const std::exception& err) {
+ error_flag = true;
+
string current_context = error_context();
if (parent) {
@@ -324,13 +328,16 @@ std::streamsize instance_t::read_line(char *& line)
return 0;
}
-void instance_t::read_next_directive()
+void instance_t::read_next_directive(bool& error_flag)
{
char * line;
std::streamsize len = read_line(line);
if (len == 0 || line == NULL)
return;
+ if (! std::isspace(line[0]))
+ error_flag = false;
+
switch (line[0]) {
case '\0':
assert(false); // shouldn't ever reach here
@@ -338,7 +345,9 @@ void instance_t::read_next_directive()
case ' ':
case '\t':
- throw parse_error(_("Unexpected whitespace at beginning of line"));
+ if (! error_flag)
+ throw parse_error(_("Unexpected whitespace at beginning of line"));
+ break;
case ';': // comments
case '#':