summaryrefslogtreecommitdiff
path: root/src/precmd.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-09 17:27:26 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-09 17:27:26 -0400
commitcad86ed87f3548aaf9d35890f2b686c2bf064368 (patch)
tree55804f88e7d69f870f6e9a0024b99889e6f6797a /src/precmd.cc
parentfd53d12bf8e5be9cf52420843418d7526ee366f9 (diff)
downloadfork-ledger-cad86ed87f3548aaf9d35890f2b686c2bf064368.tar.gz
fork-ledger-cad86ed87f3548aaf9d35890f2b686c2bf064368.tar.bz2
fork-ledger-cad86ed87f3548aaf9d35890f2b686c2bf064368.zip
For the "parse" pre-command, provide a sample transaction context.
Diffstat (limited to 'src/precmd.cc')
-rw-r--r--src/precmd.cc30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/precmd.cc b/src/precmd.cc
index 0e439b64..b4144779 100644
--- a/src/precmd.cc
+++ b/src/precmd.cc
@@ -64,23 +64,45 @@ value_t parse_command(call_scope_t& args)
report_t& report(find_scope<report_t>(args));
std::ostream& out(report.output_stream);
+ {
+ string str;
+ {
+ std::ostringstream buf;
+
+ buf << "2004/05/27 Book Store\n"
+ << " Expenses:Books 20 BOOK @ $10\n"
+ << " Liabilities:MasterCard $-200.00\n";
+
+ str = buf.str();
+ }
+ out << "--- Context is first transaction of the following entry ---"
+ << std::endl << str << std::endl;
+ {
+ std::istringstream in(str);
+ report.session.journal->parse(in, report.session, NULL, NULL);
+ }
+ }
+ entry_t * first = report.session.journal->entries.front();
+ xact_t * xact = first->xacts.front();
+
out << "--- Input expression ---" << std::endl;
- out << *arg << std::endl;
+ out << arg << std::endl;
out << std::endl << "--- Text as parsed ---" << std::endl;
- expr_t expr(*arg);
+ expr_t expr(arg);
expr.print(out);
out << std::endl;
out << std::endl << "--- Expression tree ---" << std::endl;
expr.dump(out);
- expr.compile(args);
+ bind_scope_t bound_scope(args, *xact);
+ expr.compile(bound_scope);
out << std::endl << "--- Compiled tree ---" << std::endl;
expr.dump(out);
out << std::endl << "--- Calculated value ---" << std::endl;
- value_t result(expr.calc(args));
+ value_t result(expr.calc());
result.dump(out);
out << std::endl;