From 4ec54b86f856c6e85446d065d2940b4244d71b8f Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 8 May 2010 02:06:06 -0400 Subject: Added any() and all() value expression macros any() matches an expression against every post in a transaction or account, and returns true if any of them are true. all() tests if all are true. For example: ledger -l 'account =~ /Expense/ & any(account =~ /MasterCard/)' reg This reports every posting affecting an Expense account (regex match), but only if some other posting in the same transaction affects the MasterCard account. Both functions also take a second boolean argument. If it is false, the "source" posting is not considered. For example: ledger -l 'any(/x/, false)' This matches any posting where a *different* posting in the same transaction contains the letter 'x'. --- src/parser.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/parser.cc') diff --git a/src/parser.cc b/src/parser.cc index 5bb06f84..e8e987cb 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -58,7 +58,10 @@ expr_t::parser_t::parse_value_term(std::istream& in, // An identifier followed by ( represents a function call tok = next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT)); if (tok.kind == token_t::LPAREN) { - ptr_op_t call_node(new op_t(op_t::O_CALL)); + op_t::kind_t kind = op_t::O_CALL; + if (ident == "any" || ident == "all") + kind = op_t::O_EXPAND; + ptr_op_t call_node(new op_t(kind)); call_node->set_left(node); node = call_node; -- cgit v1.2.3