diff options
-rw-r--r-- | src/precmd.cc | 7 | ||||
-rw-r--r-- | src/predicate.cc | 15 | ||||
-rw-r--r-- | src/predicate.h | 14 | ||||
-rw-r--r-- | src/report.cc | 7 |
4 files changed, 34 insertions, 9 deletions
diff --git a/src/precmd.cc b/src/precmd.cc index 999261fa..d6ff1ba5 100644 --- a/src/precmd.cc +++ b/src/precmd.cc @@ -226,7 +226,10 @@ value_t args_command(call_scope_t& args) args.value().dump(out); out << std::endl << std::endl; - string predicate = args_to_predicate(begin, end).text(); + std::pair<value_t::sequence_t::const_iterator, expr_t> + info = args_to_predicate(begin, end); + begin = info.first; + string predicate = info.second.text(); call_scope_t sub_args(static_cast<scope_t&>(args)); sub_args.push_back(string_value(predicate)); @@ -237,7 +240,7 @@ value_t args_command(call_scope_t& args) out << std::endl << _("====== Display predicate ======") << std::endl << std::endl; - predicate = args_to_predicate(begin, end).text(); + predicate = args_to_predicate(begin, end).second.text(); call_scope_t disp_sub_args(static_cast<scope_t&>(args)); disp_sub_args.push_back(string_value(predicate)); diff --git a/src/predicate.cc b/src/predicate.cc index 4f712904..a39aece0 100644 --- a/src/predicate.cc +++ b/src/predicate.cc @@ -140,6 +140,12 @@ query_lexer_t::token_t query_lexer_t::next_token() return token_t(token_t::TOK_META); else if (ident == "data") return token_t(token_t::TOK_META); + else if (ident == "show") { + // The "show" keyword is special, and separates a limiting predicate + // from a display predicate. + ++begin; + return token_t(token_t::END_REACHED); + } else if (ident == "expr") { // The expr keyword takes the whole of the next string as its // argument. @@ -351,11 +357,14 @@ expr_t::ptr_op_t query_parser_t::parse() return parse_query_expr(query_lexer_t::token_t::TOK_ACCOUNT); } -expr_t args_to_predicate(value_t::sequence_t::const_iterator& begin, - value_t::sequence_t::const_iterator end) +std::pair<value_t::sequence_t::const_iterator, expr_t> +args_to_predicate(value_t::sequence_t::const_iterator begin, + value_t::sequence_t::const_iterator end) { query_parser_t parser(begin, end); - return expr_t(parser.parse()); + expr_t expr(parser.parse()); + return std::pair<value_t::sequence_t::const_iterator, expr_t> + (parser.begin(), expr); } } // namespace ledger diff --git a/src/predicate.h b/src/predicate.h index e1048f83..dc39f2f2 100644 --- a/src/predicate.h +++ b/src/predicate.h @@ -98,6 +98,8 @@ public: class query_lexer_t { + friend class query_parser_t; + value_t::sequence_t::const_iterator begin; value_t::sequence_t::const_iterator end; @@ -246,10 +248,18 @@ public: : lexer(begin, end) {} expr_t::ptr_op_t parse(); + + value_t::sequence_t::const_iterator begin() const { + return lexer.begin; + } + value_t::sequence_t::const_iterator end() const { + return lexer.end; + } }; -expr_t args_to_predicate(value_t::sequence_t::const_iterator& begin, - value_t::sequence_t::const_iterator end); +std::pair<value_t::sequence_t::const_iterator, expr_t> +args_to_predicate(value_t::sequence_t::const_iterator begin, + value_t::sequence_t::const_iterator end); } // namespace ledger diff --git a/src/report.cc b/src/report.cc index febe43e3..7755c911 100644 --- a/src/report.cc +++ b/src/report.cc @@ -380,8 +380,11 @@ namespace { value_t::sequence_t::const_iterator end = args.value().as_sequence().end(); - string limit = args_to_predicate(begin, end).text(); + std::pair<value_t::sequence_t::const_iterator, expr_t> + info = args_to_predicate(begin, end); + begin = info.first; + string limit = info.second.text(); if (! limit.empty()) report.HANDLER(limit_).on(whence, limit); @@ -390,7 +393,7 @@ namespace { string display; if (begin != end) - display = args_to_predicate(begin, end).text(); + display = args_to_predicate(begin, end).second.text(); if (! display.empty()) report.HANDLER(display_).on(whence, display); |