Fixes to the new query expression parser

This commit is contained in:
John Wiegley 2009-10-28 23:07:03 -04:00
parent 9a07652fd8
commit 218a333e83
4 changed files with 34 additions and 9 deletions

View file

@ -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));

View file

@ -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,
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

View file

@ -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,9 +248,17 @@ 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,
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

View file

@ -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);