Fixed parsing of the "fixed" directive

This commit is contained in:
John Wiegley 2013-05-19 04:16:12 -05:00
parent 82345899f7
commit 6b52a1684f
3 changed files with 13 additions and 8 deletions

View file

@ -311,7 +311,8 @@ commodity_pool_t::exchange(const amount_t& amount,
} }
optional<std::pair<commodity_t *, price_point_t> > optional<std::pair<commodity_t *, price_point_t> >
commodity_pool_t::parse_price_directive(char * line, bool do_not_add_price) commodity_pool_t::parse_price_directive
(char * line, bool do_not_add_price, bool no_date)
{ {
char * date_field_ptr = line; char * date_field_ptr = line;
char * time_field_ptr = next_element(date_field_ptr); char * time_field_ptr = next_element(date_field_ptr);
@ -322,13 +323,13 @@ commodity_pool_t::parse_price_directive(char * line, bool do_not_add_price)
datetime_t datetime; datetime_t datetime;
string symbol; string symbol;
if (std::isdigit(time_field_ptr[0])) { if (! no_date && std::isdigit(time_field_ptr[0])) {
symbol_and_price = next_element(time_field_ptr); symbol_and_price = next_element(time_field_ptr);
if (! symbol_and_price) return none; if (! symbol_and_price) return none;
datetime = parse_datetime(date_field + " " + time_field_ptr); datetime = parse_datetime(date_field + " " + time_field_ptr);
} }
else if (std::isdigit(date_field_ptr[0])) { else if (! no_date && std::isdigit(date_field_ptr[0])) {
symbol_and_price = time_field_ptr; symbol_and_price = time_field_ptr;
datetime = datetime_t(parse_date(date_field)); datetime = datetime_t(parse_date(date_field));
} }

View file

@ -125,7 +125,8 @@ public:
// Parse commodity prices from a textual representation // Parse commodity prices from a textual representation
optional<std::pair<commodity_t *, price_point_t> > optional<std::pair<commodity_t *, price_point_t> >
parse_price_directive(char * line, bool do_not_add_price = false); parse_price_directive(char * line, bool do_not_add_price = false,
bool no_date = false);
commodity_t * commodity_t *
parse_price_expression(const std::string& str, parse_price_expression(const std::string& str,

View file

@ -848,7 +848,8 @@ void instance_t::apply_tag_directive(char * line)
void instance_t::apply_rate_directive(char * line) void instance_t::apply_rate_directive(char * line)
{ {
if (optional<std::pair<commodity_t *, price_point_t> > price_point = if (optional<std::pair<commodity_t *, price_point_t> > price_point =
commodity_pool_t::current_pool->parse_price_directive(trim_ws(line), true)) { commodity_pool_t::current_pool->parse_price_directive
(trim_ws(line), true, true)) {
apply_stack.push_front apply_stack.push_front
(application_t("fixed", fixed_rate_t(price_point->first, (application_t("fixed", fixed_rate_t(price_point->first,
price_point->second.price))); price_point->second.price)));
@ -1445,6 +1446,9 @@ post_t * instance_t::parse_post(char * line,
PARSE_NO_REDUCE | PARSE_SINGLE | PARSE_NO_ASSIGN, PARSE_NO_REDUCE | PARSE_SINGLE | PARSE_NO_ASSIGN,
defer_expr, &post->amount_expr); defer_expr, &post->amount_expr);
DEBUG("textual.parse", "line " << context.linenum << ": "
<< "post amount = " << post->amount);
if (! post->amount.is_null() && post->amount.has_commodity()) { if (! post->amount.is_null() && post->amount.has_commodity()) {
context.journal->register_commodity(post->amount.commodity(), post.get()); context.journal->register_commodity(post->amount.commodity(), post.get());
@ -1456,15 +1460,14 @@ post_t * instance_t::parse_post(char * line,
annotation_t details(rate.second); annotation_t details(rate.second);
details.add_flags(ANNOTATION_PRICE_FIXATED); details.add_flags(ANNOTATION_PRICE_FIXATED);
post->amount.annotate(details); post->amount.annotate(details);
DEBUG("textual.parse", "line " << context.linenum << ": "
<< "applied rate = " << post->amount);
break; break;
} }
} }
} }
} }
DEBUG("textual.parse", "line " << context.linenum << ": "
<< "post amount = " << post->amount);
if (stream.eof()) { if (stream.eof()) {
next = NULL; next = NULL;
} else { } else {