parent
37e9ec8030
commit
f4fd2ab1e5
3 changed files with 16 additions and 9 deletions
19
src/query.cc
19
src/query.cc
|
|
@ -36,7 +36,8 @@
|
||||||
|
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
query_t::lexer_t::token_t query_t::lexer_t::next_token()
|
query_t::lexer_t::token_t
|
||||||
|
query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context)
|
||||||
{
|
{
|
||||||
if (token_cache.kind != token_t::UNKNOWN) {
|
if (token_cache.kind != token_t::UNKNOWN) {
|
||||||
token_t tok = token_cache;
|
token_t tok = token_cache;
|
||||||
|
|
@ -108,8 +109,16 @@ query_t::lexer_t::token_t query_t::lexer_t::next_token()
|
||||||
return next_token();
|
return next_token();
|
||||||
goto resume;
|
goto resume;
|
||||||
|
|
||||||
case '(': ++arg_i; return token_t(token_t::LPAREN);
|
case '(':
|
||||||
case ')': ++arg_i; return token_t(token_t::RPAREN);
|
++arg_i;
|
||||||
|
if (tok_context == token_t::TOK_EXPR)
|
||||||
|
consume_whitespace = true;
|
||||||
|
return token_t(token_t::LPAREN);
|
||||||
|
case ')':
|
||||||
|
++arg_i;
|
||||||
|
if (tok_context == token_t::TOK_EXPR)
|
||||||
|
consume_whitespace = false;
|
||||||
|
return token_t(token_t::RPAREN);
|
||||||
case '&': ++arg_i; return token_t(token_t::TOK_AND);
|
case '&': ++arg_i; return token_t(token_t::TOK_AND);
|
||||||
case '|': ++arg_i; return token_t(token_t::TOK_OR);
|
case '|': ++arg_i; return token_t(token_t::TOK_OR);
|
||||||
case '!': ++arg_i; return token_t(token_t::TOK_NOT);
|
case '!': ++arg_i; return token_t(token_t::TOK_NOT);
|
||||||
|
|
@ -118,7 +127,7 @@ query_t::lexer_t::token_t query_t::lexer_t::next_token()
|
||||||
case '%': ++arg_i; return token_t(token_t::TOK_META);
|
case '%': ++arg_i; return token_t(token_t::TOK_META);
|
||||||
case '=':
|
case '=':
|
||||||
++arg_i;
|
++arg_i;
|
||||||
consume_next_arg = true;
|
consume_next = true;
|
||||||
return token_t(token_t::TOK_EQ);
|
return token_t(token_t::TOK_EQ);
|
||||||
|
|
||||||
case '\\':
|
case '\\':
|
||||||
|
|
@ -247,7 +256,7 @@ query_t::parser_t::parse_query_term(query_t::lexer_t::token_t::kind_t tok_contex
|
||||||
{
|
{
|
||||||
expr_t::ptr_op_t node;
|
expr_t::ptr_op_t node;
|
||||||
|
|
||||||
lexer_t::token_t tok = lexer.next_token();
|
lexer_t::token_t tok = lexer.next_token(tok_context);
|
||||||
switch (tok.kind) {
|
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_ONLY:
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ public:
|
||||||
TRACE_DTOR(query_t::lexer_t);
|
TRACE_DTOR(query_t::lexer_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
token_t next_token();
|
token_t next_token(token_t::kind_t tok_context = token_t::UNKNOWN);
|
||||||
void push_token(token_t tok) {
|
void push_token(token_t tok) {
|
||||||
assert(token_cache.kind == token_t::UNKNOWN);
|
assert(token_cache.kind == token_t::UNKNOWN);
|
||||||
token_cache = tok;
|
token_cache = tok;
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,6 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
case '{': {
|
case '{': {
|
||||||
in.get(c);
|
in.get(c);
|
||||||
amount_t temp;
|
amount_t temp;
|
||||||
|
|
@ -242,7 +241,6 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags)
|
||||||
value = temp;
|
value = temp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
case '!':
|
case '!':
|
||||||
in.get(c);
|
in.get(c);
|
||||||
|
|
@ -426,7 +424,7 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags)
|
||||||
throw_(parse_error, _("Failed to reset input stream"));
|
throw_(parse_error, _("Failed to reset input stream"));
|
||||||
|
|
||||||
c = static_cast<char>(in.peek());
|
c = static_cast<char>(in.peek());
|
||||||
if (std::isdigit(c) || c == '.')
|
if (! std::isalpha(c))
|
||||||
expected('\0', c);
|
expected('\0', c);
|
||||||
|
|
||||||
parse_ident(in);
|
parse_ident(in);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue