Fixes to the new query expression parser
This commit is contained in:
parent
9a07652fd8
commit
218a333e83
4 changed files with 34 additions and 9 deletions
|
|
@ -226,7 +226,10 @@ value_t args_command(call_scope_t& args)
|
||||||
args.value().dump(out);
|
args.value().dump(out);
|
||||||
out << std::endl << std::endl;
|
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));
|
call_scope_t sub_args(static_cast<scope_t&>(args));
|
||||||
sub_args.push_back(string_value(predicate));
|
sub_args.push_back(string_value(predicate));
|
||||||
|
|
@ -237,7 +240,7 @@ value_t args_command(call_scope_t& args)
|
||||||
out << std::endl << _("====== Display predicate ======")
|
out << std::endl << _("====== Display predicate ======")
|
||||||
<< std::endl << std::endl;
|
<< 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));
|
call_scope_t disp_sub_args(static_cast<scope_t&>(args));
|
||||||
disp_sub_args.push_back(string_value(predicate));
|
disp_sub_args.push_back(string_value(predicate));
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,12 @@ query_lexer_t::token_t query_lexer_t::next_token()
|
||||||
return token_t(token_t::TOK_META);
|
return token_t(token_t::TOK_META);
|
||||||
else if (ident == "data")
|
else if (ident == "data")
|
||||||
return token_t(token_t::TOK_META);
|
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") {
|
else if (ident == "expr") {
|
||||||
// The expr keyword takes the whole of the next string as its
|
// The expr keyword takes the whole of the next string as its
|
||||||
// argument.
|
// 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);
|
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>
|
||||||
value_t::sequence_t::const_iterator end)
|
args_to_predicate(value_t::sequence_t::const_iterator begin,
|
||||||
|
value_t::sequence_t::const_iterator end)
|
||||||
{
|
{
|
||||||
query_parser_t parser(begin, 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
|
} // namespace ledger
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,8 @@ public:
|
||||||
|
|
||||||
class query_lexer_t
|
class query_lexer_t
|
||||||
{
|
{
|
||||||
|
friend class query_parser_t;
|
||||||
|
|
||||||
value_t::sequence_t::const_iterator begin;
|
value_t::sequence_t::const_iterator begin;
|
||||||
value_t::sequence_t::const_iterator end;
|
value_t::sequence_t::const_iterator end;
|
||||||
|
|
||||||
|
|
@ -246,10 +248,18 @@ public:
|
||||||
: lexer(begin, end) {}
|
: lexer(begin, end) {}
|
||||||
|
|
||||||
expr_t::ptr_op_t parse();
|
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>
|
||||||
value_t::sequence_t::const_iterator end);
|
args_to_predicate(value_t::sequence_t::const_iterator begin,
|
||||||
|
value_t::sequence_t::const_iterator end);
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -380,8 +380,11 @@ namespace {
|
||||||
value_t::sequence_t::const_iterator end =
|
value_t::sequence_t::const_iterator end =
|
||||||
args.value().as_sequence().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())
|
if (! limit.empty())
|
||||||
report.HANDLER(limit_).on(whence, limit);
|
report.HANDLER(limit_).on(whence, limit);
|
||||||
|
|
||||||
|
|
@ -390,7 +393,7 @@ namespace {
|
||||||
|
|
||||||
string display;
|
string display;
|
||||||
if (begin != end)
|
if (begin != end)
|
||||||
display = args_to_predicate(begin, end).text();
|
display = args_to_predicate(begin, end).second.text();
|
||||||
|
|
||||||
if (! display.empty())
|
if (! display.empty())
|
||||||
report.HANDLER(display_).on(whence, display);
|
report.HANDLER(display_).on(whence, display);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue