summaryrefslogtreecommitdiff
path: root/textual.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-07-29 21:38:20 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-07-29 21:44:21 -0400
commit1bb29cdbb7fa63d2fd5312e3fc81bcc489aaab5d (patch)
treed5c7e3897763a8a9d4b05c438d1c1bcb8020ee04 /textual.cc
parent42e1d725aa9deb41396ba4c73c8499c7c3798508 (diff)
downloadfork-ledger-1bb29cdbb7fa63d2fd5312e3fc81bcc489aaab5d.tar.gz
fork-ledger-1bb29cdbb7fa63d2fd5312e3fc81bcc489aaab5d.tar.bz2
fork-ledger-1bb29cdbb7fa63d2fd5312e3fc81bcc489aaab5d.zip
The register report has begun printing real data, although not all the pieces
are in place yet and the formatting is still off.
Diffstat (limited to 'textual.cc')
-rw-r--r--textual.cc62
1 files changed, 23 insertions, 39 deletions
diff --git a/textual.cc b/textual.cc
index 37c03c06..cb862ee7 100644
--- a/textual.cc
+++ b/textual.cc
@@ -68,20 +68,10 @@ namespace {
#endif
if (expr) {
- expr.compile(*xact);
-
- if (expr.is_constant()) {
- amount = expr.constant_value().as_amount();
- DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
- "The transaction amount is " << amount);
- return expr_t(); // we will fill this in with text
- } else {
- if (SHOW_DEBUG("ledger.textual.parse")) {
- std::cout << "Value expression tree:" << std::endl;
- expr.dump(std::cout);
- }
- return expr;
- }
+ amount = expr.calc(*xact).as_amount();
+ DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
+ "The transaction amount is " << amount);
+ return expr;
}
return none;
}
@@ -189,9 +179,12 @@ xact_t * parse_xact(char * line, account_t * account,
"Reduced amount is " << xact->amount);
}
- // jww (2008-07-24): I don't think this is right, since amount_expr is
- // always NULL right now
+ // We don't need to store the actual expression that resulted in the
+ // amount if it's constant
if (xact->amount_expr) {
+ if (xact->amount_expr->is_constant())
+ xact->amount_expr = expr_t();
+
unsigned long end = (long)in.tellg();
xact->amount_expr->set_text(string(line, beg, end - beg));
}
@@ -228,28 +221,19 @@ xact_t * parse_xact(char * line, account_t * account,
try {
unsigned long beg = (long)in.tellg();
- if (optional<expr_t> cost_expr =
- parse_amount_expr(in, *xact->cost, xact.get(),
- EXPR_PARSE_NO_MIGRATE |
- EXPR_PARSE_NO_ASSIGN)) {
- try {
- *xact->cost = cost_expr->calc(*xact).as_amount();
- assert(xact->cost->valid());
-
- xact->cost_expr = cost_expr;
-
- unsigned long end = (long)in.tellg();
- if (per_unit)
- xact->cost_expr->set_text(string("@") +
- string(line, beg, end - beg));
- else
- xact->cost_expr->set_text(string("@@") +
- string(line, beg, end - beg));
- }
- catch (...) {
- throw new parse_error
- ("A transaction's cost must evaluate to a constant value");
- }
+ xact->cost_expr =
+ parse_amount_expr(in, *xact->cost, xact.get(),
+ EXPR_PARSE_NO_MIGRATE |
+ EXPR_PARSE_NO_ASSIGN);
+
+ if (xact->cost_expr) {
+ unsigned long end = (long)in.tellg();
+ if (per_unit)
+ xact->cost_expr->set_text(string("@") +
+ string(line, beg, end - beg));
+ else
+ xact->cost_expr->set_text(string("@@") +
+ string(line, beg, end - beg));
}
}
catch (error * err) {
@@ -290,7 +274,7 @@ xact_t * parse_xact(char * line, account_t * account,
account_xdata_t& xdata(account_xdata(*xact->account));
- if (xact->amount) {
+ if (! xact->amount.is_null()) {
if (xdata.value.is_null())
xdata.value = xact->amount;
else