summaryrefslogtreecommitdiff
path: root/main.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-08-01 02:53:32 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-08-01 02:53:32 -0400
commitaf344b1ab145f043178a473b2ad32f88a8c74442 (patch)
treeee73595cde729810bab002725300a1cbd33ceb32 /main.cc
parentd213b32ffc6adaffa8e9ea4081b47c7b9403112c (diff)
downloadfork-ledger-af344b1ab145f043178a473b2ad32f88a8c74442.tar.gz
fork-ledger-af344b1ab145f043178a473b2ad32f88a8c74442.tar.bz2
fork-ledger-af344b1ab145f043178a473b2ad32f88a8c74442.zip
Improved the output from some debugging commands.
There are now three commands one can use to interact with value expressions directly: ledger parse EXPR # shows the parse tree resulting from EXPR ledger compile EXPR # shows what the compiled tree looks like ledger eval EXPR # print the resulting value, useful in scripts
Diffstat (limited to 'main.cc')
-rw-r--r--main.cc55
1 files changed, 38 insertions, 17 deletions
diff --git a/main.cc b/main.cc
index 8d9f64dd..7356a958 100644
--- a/main.cc
+++ b/main.cc
@@ -170,30 +170,51 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[],
if (verb == "parse") {
expr_t expr(*arg);
- IF_INFO() {
- std::cout << "Value expression tree:" << std::endl;
- expr.dump(std::cout);
- std::cout << std::endl;
+ *out << "Value expression as input: " << *arg << std::endl;
+
+ *out << "Value expression as parsed: ";
+ expr.print(*out, report);
+ *out << std::endl;
- std::cout << "Value expression parsed was:" << std::endl;
- expr.print(std::cout, report);
- std::cout << std::endl << std::endl;
+ *out << std::endl;
+ *out << "--- Parsed tree ---" << std::endl;
+ expr.dump(*out);
- expr.compile(report);
+ *out << std::endl;
+ *out << "--- Calculated value ---" << std::endl;
+ expr.calc(report).print(*out);
+ *out << std::endl;
- std::cout << "Value expression after compiling:" << std::endl;
- expr.dump(std::cout);
- std::cout << std::endl;
+ return 0;
+ }
+ else if (verb == "compile") {
+ expr_t expr(*arg);
- std::cout << "Value expression is now:" << std::endl;
- expr.print(std::cout, report);
- std::cout << std::endl << std::endl;
+ *out << "Value expression as input: " << *arg << std::endl;
+ *out << "Value expression as parsed: ";
+ expr.print(*out, report);
+ *out << std::endl;
- std::cout << "Result of calculation: ";
- }
+ *out << std::endl;
+ *out << "--- Parsed tree ---" << std::endl;
+ expr.dump(*out);
- std::cout << expr.calc(report).strip_annotations() << std::endl;
+ expr.compile(report);
+ *out << std::endl;
+ *out << "--- Compiled tree ---" << std::endl;
+ expr.dump(*out);
+
+ *out << std::endl;
+ *out << "--- Calculated value ---" << std::endl;
+ expr.calc(report).print(*out);
+ *out << std::endl;
+
+ return 0;
+ }
+ else if (verb == "eval") {
+ expr_t expr(*arg);
+ *out << expr.calc(report).strip_annotations() << std::endl;
return 0;
}