Implemented a text parsing optimization.
Amounts, costs and assigned amounts are now parsed as regular amounts. To have a full value expression at any of those positions, surround it with parentheses. The reason for this is that the amount parser is far simpler and quicker -- and by far the common case -- compared to the full expression parser.
This commit is contained in:
parent
dfe04b9943
commit
6bd82c6bcd
1 changed files with 54 additions and 43 deletions
|
|
@ -756,12 +756,15 @@ xact_t * textual_parser_t::instance_t::parse_xact(char * line,
|
||||||
goto parse_assign;
|
goto parse_assign;
|
||||||
|
|
||||||
beg = in.tellg();
|
beg = in.tellg();
|
||||||
|
saw_amount = true;
|
||||||
|
|
||||||
|
if (p != '(') { // indicates a value expression
|
||||||
|
xact->amount.parse(in, amount_t::PARSE_NO_REDUCE);
|
||||||
|
} else {
|
||||||
xact->amount_expr =
|
xact->amount_expr =
|
||||||
parse_amount_expr(in, xact->amount, xact.get(),
|
parse_amount_expr(in, xact->amount, xact.get(),
|
||||||
static_cast<uint_least8_t>(expr_t::PARSE_NO_REDUCE) |
|
static_cast<uint_least8_t>(expr_t::PARSE_NO_REDUCE) |
|
||||||
static_cast<uint_least8_t>(expr_t::PARSE_NO_ASSIGN));
|
static_cast<uint_least8_t>(expr_t::PARSE_NO_ASSIGN));
|
||||||
saw_amount = true;
|
|
||||||
|
|
||||||
if (! xact->amount.is_null()) {
|
if (! xact->amount.is_null()) {
|
||||||
xact->amount.reduce();
|
xact->amount.reduce();
|
||||||
|
|
@ -779,6 +782,7 @@ xact_t * textual_parser_t::instance_t::parse_xact(char * line,
|
||||||
xact->amount_expr->set_text(string(line, long(beg), long(end - beg)));
|
xact->amount_expr->set_text(string(line, long(beg), long(end - beg)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the optional cost (@ PER-UNIT-COST, @@ TOTAL-COST)
|
// Parse the optional cost (@ PER-UNIT-COST, @@ TOTAL-COST)
|
||||||
|
|
||||||
|
|
@ -786,8 +790,7 @@ xact_t * textual_parser_t::instance_t::parse_xact(char * line,
|
||||||
p = peek_next_nonws(in);
|
p = peek_next_nonws(in);
|
||||||
if (p == '@') {
|
if (p == '@') {
|
||||||
if (! saw_amount)
|
if (! saw_amount)
|
||||||
throw parse_error
|
throw parse_error("Transaction cannot have a cost without an amount");
|
||||||
("Transaction cannot have a cost expression with an amount");
|
|
||||||
|
|
||||||
DEBUG("textual.parse", "line " << linenum << ": " <<
|
DEBUG("textual.parse", "line " << linenum << ": " <<
|
||||||
"Found a price indicator");
|
"Found a price indicator");
|
||||||
|
|
@ -805,6 +808,9 @@ xact_t * textual_parser_t::instance_t::parse_xact(char * line,
|
||||||
|
|
||||||
beg = in.tellg();
|
beg = in.tellg();
|
||||||
|
|
||||||
|
if (p != '(') { // indicates a value expression
|
||||||
|
xact->cost->parse(in, amount_t::PARSE_NO_MIGRATE);
|
||||||
|
} else {
|
||||||
xact->cost_expr =
|
xact->cost_expr =
|
||||||
parse_amount_expr(in, *xact->cost, xact.get(),
|
parse_amount_expr(in, *xact->cost, xact.get(),
|
||||||
static_cast<uint_least8_t>(expr_t::PARSE_NO_MIGRATE) |
|
static_cast<uint_least8_t>(expr_t::PARSE_NO_MIGRATE) |
|
||||||
|
|
@ -819,6 +825,7 @@ xact_t * textual_parser_t::instance_t::parse_xact(char * line,
|
||||||
xact->cost_expr->set_text(string("@@") +
|
xact->cost_expr->set_text(string("@@") +
|
||||||
string(line, long(beg), long(end - beg)));
|
string(line, long(beg), long(end - beg)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (xact->cost->sign() < 0)
|
if (xact->cost->sign() < 0)
|
||||||
throw parse_error("A transaction's cost may not be negative");
|
throw parse_error("A transaction's cost may not be negative");
|
||||||
|
|
@ -857,6 +864,9 @@ xact_t * textual_parser_t::instance_t::parse_xact(char * line,
|
||||||
|
|
||||||
beg = in.tellg();
|
beg = in.tellg();
|
||||||
|
|
||||||
|
if (p != '(') { // indicates a value expression
|
||||||
|
xact->assigned_amount->parse(in, amount_t::PARSE_NO_MIGRATE);
|
||||||
|
} else {
|
||||||
xact->assigned_amount_expr =
|
xact->assigned_amount_expr =
|
||||||
parse_amount_expr(in, *xact->assigned_amount, xact.get(),
|
parse_amount_expr(in, *xact->assigned_amount, xact.get(),
|
||||||
static_cast<uint_least8_t>(expr_t::PARSE_NO_MIGRATE));
|
static_cast<uint_least8_t>(expr_t::PARSE_NO_MIGRATE));
|
||||||
|
|
@ -873,6 +883,7 @@ xact_t * textual_parser_t::instance_t::parse_xact(char * line,
|
||||||
xact->assigned_amount_expr->set_text
|
xact->assigned_amount_expr->set_text
|
||||||
(string("=") + string(line, long(beg), long(end - beg)));
|
(string("=") + string(line, long(beg), long(end - beg)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
account_t::xdata_t& xdata(xact->account->xdata());
|
account_t::xdata_t& xdata(xact->account->xdata());
|
||||||
amount_t& amt(*xact->assigned_amount);
|
amount_t& amt(*xact->assigned_amount);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue