Improved error reports about leading whitespace

This commit is contained in:
John Wiegley 2012-03-16 03:50:40 -05:00
parent dc91d4f1e6
commit 20c076dff9
5 changed files with 51 additions and 1178 deletions

View file

@ -133,7 +133,7 @@ namespace {
} }
#endif #endif
void read_next_directive(); void read_next_directive(bool& error_flag);
#if defined(TIMELOG_SUPPORT) #if defined(TIMELOG_SUPPORT)
void clock_in_directive(char * line, bool capitalized); void clock_in_directive(char * line, bool capitalized);
@ -251,11 +251,15 @@ void instance_t::parse()
context.linenum = 0; context.linenum = 0;
context.curr_pos = in.tellg(); context.curr_pos = in.tellg();
bool error_flag = false;
while (in.good() && ! in.eof()) { while (in.good() && ! in.eof()) {
try { try {
read_next_directive(); read_next_directive(error_flag);
} }
catch (const std::exception& err) { catch (const std::exception& err) {
error_flag = true;
string current_context = error_context(); string current_context = error_context();
if (parent) { if (parent) {
@ -324,13 +328,16 @@ std::streamsize instance_t::read_line(char *& line)
return 0; return 0;
} }
void instance_t::read_next_directive() void instance_t::read_next_directive(bool& error_flag)
{ {
char * line; char * line;
std::streamsize len = read_line(line); std::streamsize len = read_line(line);
if (len == 0 || line == NULL) if (len == 0 || line == NULL)
return; return;
if (! std::isspace(line[0]))
error_flag = false;
switch (line[0]) { switch (line[0]) {
case '\0': case '\0':
assert(false); // shouldn't ever reach here assert(false); // shouldn't ever reach here
@ -338,7 +345,9 @@ void instance_t::read_next_directive()
case ' ': case ' ':
case '\t': case '\t':
if (! error_flag)
throw parse_error(_("Unexpected whitespace at beginning of line")); throw parse_error(_("Unexpected whitespace at beginning of line"));
break;
case ';': // comments case ';': // comments
case '#': case '#':

File diff suppressed because it is too large Load diff

View file

@ -10,12 +10,8 @@
Asset:Bank:Boi:Savings:Dk -3016.24 Asset:Bank:Boi:Savings:Dk -3016.24
Income:NetSalary:Dk Income:NetSalary:Dk
test reg -> 3 test reg -> 1
__ERROR__ __ERROR__
While parsing file "$sourcepath/test/regress/8EAF77C0.test", line 5: While parsing file "$sourcepath/test/regress/8EAF77C0.test", line 5:
Error: Unexpected whitespace at beginning of line Error: Unexpected whitespace at beginning of line
While parsing file "$sourcepath/test/regress/8EAF77C0.test", line 6:
Error: Unexpected whitespace at beginning of line
While parsing file "$sourcepath/test/regress/8EAF77C0.test", line 7:
Error: Unexpected whitespace at beginning of line
end test end test

View file

@ -0,0 +1,12 @@
2011-02-23 Rocket Fuel
Expense:Travel $100000000.00 ; trip: Moon
Asset:NASA
2011-02-23 Liquid Oxygen
Expense:Travel $232233223.00 ; trip: Moon
Asset:NASA
test bal --group-by "tag('trip')"
Moon
$332233223.00 Expense:Travel
end test

View file

@ -0,0 +1,24 @@
2012-03-16 KFC
Expenses:Food $-20
Assets:Cash
2012-03-16 KFC
Expenses:Food $- 20
Assets:Cash
2012-03-16 KFC
Expenses:Food -$20
Assets:Cash
2012-03-16 KFC
Expenses:Food - $20
Assets:Cash
test reg -> 1
__ERROR__
While parsing file "$sourcepath/test/regress/D51BFF74.test", line 6:
While parsing posting:
Expenses:Food $- 20
^^^^^
Error: No quantity specified for amount
end test