summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-24 00:30:18 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-24 00:30:18 -0400
commit129b2de901ccfaa01f7c4a520c91787d83291ec3 (patch)
tree5a6cc53a14b5f7384c4cc54839542fe9f0b645b9
parenteda6cbd0146d371653feec70e0eb3ee4e4c56379 (diff)
downloadfork-ledger-129b2de901ccfaa01f7c4a520c91787d83291ec3.tar.gz
fork-ledger-129b2de901ccfaa01f7c4a520c91787d83291ec3.tar.bz2
fork-ledger-129b2de901ccfaa01f7c4a520c91787d83291ec3.zip
"only" now a report query modifier for --only
This fits with "show" and "bold", etc.
-rw-r--r--src/query.cc42
-rw-r--r--src/query.h4
-rw-r--r--src/report.cc5
3 files changed, 31 insertions, 20 deletions
diff --git a/src/query.cc b/src/query.cc
index bed6afae..5480336c 100644
--- a/src/query.cc
+++ b/src/query.cc
@@ -186,6 +186,8 @@ test_ident:
return token_t(token_t::TOK_META);
else if (ident == "show")
return token_t(token_t::TOK_SHOW);
+ else if (ident == "only")
+ return token_t(token_t::TOK_ONLY);
else if (ident == "bold")
return token_t(token_t::TOK_BOLD);
else if (ident == "for")
@@ -249,6 +251,7 @@ query_t::parser_t::parse_query_term(query_t::lexer_t::token_t::kind_t tok_contex
lexer_t::token_t tok = lexer.next_token();
switch (tok.kind) {
case lexer_t::token_t::TOK_SHOW:
+ case lexer_t::token_t::TOK_ONLY:
case lexer_t::token_t::TOK_BOLD:
case lexer_t::token_t::TOK_FOR:
case lexer_t::token_t::TOK_SINCE:
@@ -452,9 +455,26 @@ query_t::parser_t::parse_query_expr(lexer_t::token_t::kind_t tok_context,
lexer_t::token_t tok = lexer.peek_token();
while (tok.kind != lexer_t::token_t::END_REACHED) {
switch (tok.kind) {
- case lexer_t::token_t::TOK_SHOW: {
+ case lexer_t::token_t::TOK_SHOW:
+ case lexer_t::token_t::TOK_ONLY:
+ case lexer_t::token_t::TOK_BOLD: {
lexer.next_token();
+ kind_t kind;
+ switch (tok.kind) {
+ case lexer_t::token_t::TOK_SHOW:
+ kind = QUERY_SHOW;
+ break;
+ case lexer_t::token_t::TOK_ONLY:
+ kind = QUERY_ONLY;
+ break;
+ case lexer_t::token_t::TOK_BOLD:
+ kind = QUERY_BOLD;
+ break;
+ default:
+ break;
+ }
+
expr_t::ptr_op_t node;
while (expr_t::ptr_op_t next = parse_or_expr(tok_context)) {
if (! node) {
@@ -470,25 +490,7 @@ query_t::parser_t::parse_query_expr(lexer_t::token_t::kind_t tok_context,
if (node)
query_map.insert
(query_map_t::value_type
- (QUERY_SHOW, predicate_t(node, what_to_keep).print_to_str()));
- break;
- }
-
- case lexer_t::token_t::TOK_BOLD: {
- lexer.next_token();
-
- expr_t::ptr_op_t node = parse_or_expr(tok_context);
- while (expr_t::ptr_op_t next = parse_or_expr(tok_context)) {
- expr_t::ptr_op_t prev(node);
- node = new expr_t::op_t(expr_t::op_t::O_OR);
- node->set_left(prev);
- node->set_right(next);
- }
-
- if (node)
- query_map.insert
- (query_map_t::value_type
- (QUERY_BOLD, predicate_t(node, what_to_keep).print_to_str()));
+ (kind, predicate_t(node, what_to_keep).print_to_str()));
break;
}
diff --git a/src/query.h b/src/query.h
index 5a4651a0..b5b3b0fc 100644
--- a/src/query.h
+++ b/src/query.h
@@ -90,6 +90,7 @@ public:
TOK_EXPR,
TOK_SHOW,
+ TOK_ONLY,
TOK_BOLD,
TOK_FOR,
TOK_SINCE,
@@ -144,6 +145,7 @@ public:
case TOK_META: return "TOK_META";
case TOK_EXPR: return "TOK_EXPR";
case TOK_SHOW: return "TOK_SHOW";
+ case TOK_ONLY: return "TOK_ONLY";
case TOK_BOLD: return "TOK_BOLD";
case TOK_FOR: return "TOK_FOR";
case TOK_SINCE: return "TOK_SINCE";
@@ -170,6 +172,7 @@ public:
case TOK_META: return "meta";
case TOK_EXPR: return "expr";
case TOK_SHOW: return "show";
+ case TOK_ONLY: return "only";
case TOK_BOLD: return "bold";
case TOK_FOR: return "for";
case TOK_SINCE: return "since";
@@ -234,6 +237,7 @@ public:
enum kind_t {
QUERY_LIMIT,
QUERY_SHOW,
+ QUERY_ONLY,
QUERY_BOLD,
QUERY_FOR
};
diff --git a/src/report.cc b/src/report.cc
index 9d733674..b9ed540c 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -267,6 +267,11 @@ void report_t::parse_query_args(const value_t& args, const string& whence)
DEBUG("report.predicate", "Limit predicate = " << HANDLER(limit_).str());
}
+ if (query.has_query(query_t::QUERY_ONLY)) {
+ HANDLER(only_).on(whence, query.get_query(query_t::QUERY_ONLY));
+ DEBUG("report.predicate", "Only predicate = " << HANDLER(only_).str());
+ }
+
if (query.has_query(query_t::QUERY_SHOW)) {
HANDLER(display_).on(whence, query.get_query(query_t::QUERY_SHOW));
DEBUG("report.predicate", "Display predicate = " << HANDLER(display_).str());