From af344b1ab145f043178a473b2ad32f88a8c74442 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 1 Aug 2008 02:53:32 -0400 Subject: 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 --- main.cc | 55 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'main.cc') 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; } -- cgit v1.2.3