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
This commit is contained in:
parent
d213b32ffc
commit
af344b1ab1
4 changed files with 49 additions and 24 deletions
55
main.cc
55
main.cc
|
|
@ -170,30 +170,51 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[],
|
||||||
if (verb == "parse") {
|
if (verb == "parse") {
|
||||||
expr_t expr(*arg);
|
expr_t expr(*arg);
|
||||||
|
|
||||||
IF_INFO() {
|
*out << "Value expression as input: " << *arg << std::endl;
|
||||||
std::cout << "Value expression tree:" << std::endl;
|
|
||||||
expr.dump(std::cout);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << "Value expression parsed was:" << std::endl;
|
*out << "Value expression as parsed: ";
|
||||||
expr.print(std::cout, report);
|
expr.print(*out, report);
|
||||||
std::cout << std::endl << std::endl;
|
*out << std::endl;
|
||||||
|
|
||||||
expr.compile(report);
|
*out << std::endl;
|
||||||
|
*out << "--- Parsed tree ---" << std::endl;
|
||||||
|
expr.dump(*out);
|
||||||
|
|
||||||
std::cout << "Value expression after compiling:" << std::endl;
|
*out << std::endl;
|
||||||
expr.dump(std::cout);
|
*out << "--- Calculated value ---" << std::endl;
|
||||||
std::cout << std::endl;
|
expr.calc(report).print(*out);
|
||||||
|
*out << std::endl;
|
||||||
|
|
||||||
std::cout << "Value expression is now:" << std::endl;
|
return 0;
|
||||||
expr.print(std::cout, report);
|
}
|
||||||
std::cout << std::endl << std::endl;
|
else if (verb == "compile") {
|
||||||
|
expr_t expr(*arg);
|
||||||
|
|
||||||
std::cout << "Result of calculation: ";
|
*out << "Value expression as input: " << *arg << std::endl;
|
||||||
}
|
*out << "Value expression as parsed: ";
|
||||||
|
expr.print(*out, report);
|
||||||
|
*out << std::endl;
|
||||||
|
|
||||||
std::cout << expr.calc(report).strip_annotations() << std::endl;
|
*out << std::endl;
|
||||||
|
*out << "--- Parsed tree ---" << std::endl;
|
||||||
|
expr.dump(*out);
|
||||||
|
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
9
op.cc
9
op.cc
|
|
@ -754,9 +754,12 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
||||||
return ! left()->calc(scope);
|
return ! left()->calc(scope);
|
||||||
|
|
||||||
case O_AND:
|
case O_AND:
|
||||||
return left()->calc(scope) && right()->calc(scope);
|
return ! left()->calc(scope) ? value_t(false) : right()->calc(scope);
|
||||||
case O_OR:
|
case O_OR:
|
||||||
return left()->calc(scope) || right()->calc(scope);
|
if (value_t temp = left()->calc(scope))
|
||||||
|
return temp;
|
||||||
|
else
|
||||||
|
return right()->calc(scope);
|
||||||
|
|
||||||
case O_COMMA: {
|
case O_COMMA: {
|
||||||
value_t result(left()->calc(scope));
|
value_t result(left()->calc(scope));
|
||||||
|
|
@ -976,7 +979,7 @@ void expr_t::op_t::dump(std::ostream& out, const int depth) const
|
||||||
{
|
{
|
||||||
out.setf(std::ios::left);
|
out.setf(std::ios::left);
|
||||||
out.width(10);
|
out.width(10);
|
||||||
out << this << " ";
|
out << this;
|
||||||
|
|
||||||
for (int i = 0; i < depth; i++)
|
for (int i = 0; i < depth; i++)
|
||||||
out << " ";
|
out << " ";
|
||||||
|
|
|
||||||
7
op.h
7
op.h
|
|
@ -275,11 +275,12 @@ public:
|
||||||
unsigned long * start_pos;
|
unsigned long * start_pos;
|
||||||
unsigned long * end_pos;
|
unsigned long * end_pos;
|
||||||
|
|
||||||
print_context_t(scope_t& _scope,
|
// jww (2008-08-01): Is a scope needed here?
|
||||||
const bool _relaxed = false,
|
print_context_t(scope_t& _scope,
|
||||||
|
const bool _relaxed = false,
|
||||||
const ptr_op_t& _op_to_find = ptr_op_t(),
|
const ptr_op_t& _op_to_find = ptr_op_t(),
|
||||||
unsigned long * _start_pos = NULL,
|
unsigned long * _start_pos = NULL,
|
||||||
unsigned long * _end_pos = NULL)
|
unsigned long * _end_pos = NULL)
|
||||||
: scope(_scope), relaxed(_relaxed), op_to_find(_op_to_find),
|
: scope(_scope), relaxed(_relaxed), op_to_find(_op_to_find),
|
||||||
start_pos(_start_pos), end_pos(_end_pos) {}
|
start_pos(_start_pos), end_pos(_end_pos) {}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
2
report.h
2
report.h
|
|
@ -240,7 +240,7 @@ public:
|
||||||
}
|
}
|
||||||
value_t option_bar(call_scope_t& args) {
|
value_t option_bar(call_scope_t& args) {
|
||||||
std::cout << "This is bar: " << args[0] << std::endl;
|
std::cout << "This is bar: " << args[0] << std::endl;
|
||||||
return NULL_VALUE;
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue