Merge pull request #356 from afh/pull/1038
Fix bug 1038; Improve error handling when parsing year directives
This commit is contained in:
commit
dafb99df0d
4 changed files with 82 additions and 9 deletions
|
|
@ -285,6 +285,11 @@ void instance_t::parse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (apply_stack.front().value.type() == typeid(optional<datetime_t>))
|
||||||
|
epoch = boost::get<optional<datetime_t> >(apply_stack.front().value);
|
||||||
|
|
||||||
|
apply_stack.pop_front();
|
||||||
|
|
||||||
#if defined(TIMELOG_SUPPORT)
|
#if defined(TIMELOG_SUPPORT)
|
||||||
timelog.close();
|
timelog.close();
|
||||||
#endif // TIMELOG_SUPPORT
|
#endif // TIMELOG_SUPPORT
|
||||||
|
|
@ -419,7 +424,9 @@ void instance_t::read_next_directive(bool& error_flag)
|
||||||
price_xact_directive(line);
|
price_xact_directive(line);
|
||||||
break;
|
break;
|
||||||
case 'Y': // set the current year
|
case 'Y': // set the current year
|
||||||
apply_year_directive(line + 1);
|
if (std::strlen(line+1) == 0)
|
||||||
|
throw_(parse_error, _f("Directive '%1%' requires an argument") % line[0]);
|
||||||
|
apply_year_directive(line+1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -863,14 +870,17 @@ void instance_t::apply_rate_directive(char * line)
|
||||||
|
|
||||||
void instance_t::apply_year_directive(char * line)
|
void instance_t::apply_year_directive(char * line)
|
||||||
{
|
{
|
||||||
apply_stack.push_front(application_t("year", epoch));
|
try {
|
||||||
|
unsigned short year(lexical_cast<unsigned short>(skip_ws(line)));
|
||||||
// This must be set to the last day of the year, otherwise partial
|
apply_stack.push_front(application_t("year", epoch));
|
||||||
// dates like "11/01" will refer to last year's november, not the
|
DEBUG("times.epoch", "Setting current year to " << year);
|
||||||
// current year.
|
// This must be set to the last day of the year, otherwise partial
|
||||||
unsigned short year(lexical_cast<unsigned short>(skip_ws(line)));
|
// dates like "11/01" will refer to last year's november, not the
|
||||||
DEBUG("times.epoch", "Setting current year to " << year);
|
// current year.
|
||||||
epoch = datetime_t(date_t(year, 12, 31));
|
epoch = datetime_t(date_t(year, 12, 31));
|
||||||
|
} catch(bad_lexical_cast &) {
|
||||||
|
throw_(parse_error, _f("Argument '%1%' not a valid year") % skip_ws(line));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void instance_t::end_apply_directive(char * kind)
|
void instance_t::end_apply_directive(char * kind)
|
||||||
|
|
@ -1375,6 +1385,13 @@ bool instance_t::general_directive(char * line)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
if (std::strcmp(p, "year") == 0) {
|
||||||
|
apply_year_directive(arg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expr_t::ptr_op_t op = lookup(symbol_t::DIRECTIVE, p)) {
|
if (expr_t::ptr_op_t op = lookup(symbol_t::DIRECTIVE, p)) {
|
||||||
|
|
|
||||||
18
test/regress/1038_1.test
Normal file
18
test/regress/1038_1.test
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
Y2014
|
||||||
|
|
||||||
|
04/13 Bank
|
||||||
|
Expenses:Loan $400
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
05/13 Bug 1038 Test
|
||||||
|
Expenses:Some:Account $500
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
06/13 Landlord
|
||||||
|
Expenses:Rent $600
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
test reg --now 2014-05-14 -p 'this month'
|
||||||
|
14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500
|
||||||
|
Assets:Cash $-500 0
|
||||||
|
end test
|
||||||
18
test/regress/1038_2.test
Normal file
18
test/regress/1038_2.test
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
year 2014
|
||||||
|
|
||||||
|
04/13 Bank
|
||||||
|
Expenses:Loan $400
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
05/13 Bug 1038 Test
|
||||||
|
Expenses:Some:Account $500
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
06/13 Landlord
|
||||||
|
Expenses:Rent $600
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
test reg --now 2014-05-14 -p 'this month'
|
||||||
|
14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500
|
||||||
|
Assets:Cash $-500 0
|
||||||
|
end test
|
||||||
20
test/regress/1038_3.test
Normal file
20
test/regress/1038_3.test
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
apply year 2014
|
||||||
|
|
||||||
|
04/13 Bank
|
||||||
|
Expenses:Loan $400
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
05/13 Bug 1038 Test
|
||||||
|
Expenses:Some:Account $500
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
06/13 Landlord
|
||||||
|
Expenses:Rent $600
|
||||||
|
Assets:Cash
|
||||||
|
|
||||||
|
end apply
|
||||||
|
|
||||||
|
test reg --now 2014-05-14 -p 'this month'
|
||||||
|
14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500
|
||||||
|
Assets:Cash $-500 0
|
||||||
|
end test
|
||||||
Loading…
Add table
Reference in a new issue